• 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的时候完成的,

  • 相关阅读:
    匹配下拉控件
    验证视图状态 MAC 失败
    打开网页要输入用户名和密码的解决方案!
    ASP.NET网站安装部署参考总结!
    IOS开发中常量的处理
    typedef与define的区别
    OC的单例模式
    js for循环中传入动态参数
    javascript array map方法
    javascript 得到兄弟节点的方法,jquery妙用
  • 原文地址:https://www.cnblogs.com/daaiwusehng/p/5386831.html
Copyright © 2020-2023  润新知