zoukankan      html  css  js  c++  java
  • animateWithDuration 这样的方法,在第二次应用到某个view上动画时间无效问题

    @interface ViewController ()

    @property (nonatomic, strong)UIButton * viewRed;

    @end

    @implementation ViewController

    -(UIView *)viewRed

    {

        if (!_viewRed) {

            _viewRed = [[UIButton alloc]initWithFrame:CGRectMake( 0,self.view.frame.size.height, 300, 80)];

            _viewRed.backgroundColor = [UIColor redColor];

            [_viewRed addTarget:self action:@selector(hiddenRedView) forControlEvents:UIControlEventTouchUpInside];

        }

        return _viewRed;

    }

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(animateAction)];

        [self.view addGestureRecognizer:tap];

        

        [self.view addSubview:self.viewRed];

    }

    - (void)hiddenRedView

    {

        [self.viewRed removeFromSuperview];

    }

    -(void)animateAction

    {

        [self.view addSubview:self.viewRed];

        self.viewRed.transform = CGAffineTransformIdentity;

        [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{

            CGAffineTransform transform = CGAffineTransformMakeTranslation(0, -80);

            self.viewRed.transform = transform;

            NSLog(@"%@",self.viewRed);

        } completion:^(BOOL finished) {

            NSLog(@"%@",self.viewRed);

        }];

    }

    //*******************************

    上面这段代码如果不加入 self.viewRed.transform = CGAffineTransformIdentity;

    这句话,那么第二次点击屏幕时,动画看样子是在time为0的时候完成的,

  • 相关阅读:
    SQL Server中的sysobjects
    SQL:事务(1)
    继续探究HTML与CSS:图像映射
    SQL:事务(2)
    找工作?该复习了!(转)
    继续探究HTML与CSS:!important 和 @import 规则
    JAVA数据结构:二叉树
    SQL:Like 通配符及特殊用法Escape
    JavaScript高级程序设计:在HTML中使用JavaScript
    一个有趣的时钟
  • 原文地址:https://www.cnblogs.com/daaiwusehng/p/5386831.html
Copyright © 2011-2022 走看看