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

  • 相关阅读:
    JavaScript 正则表达式中的特殊字符
    framework —— throttles(访问频率控制)
    framework —— permission(权限)
    framework —— auth认证
    算法——基础知识
    算法——解迷宫
    算法
    爬虫 ==》 同步调用
    asyncio模块
    Requests模块
  • 原文地址:https://www.cnblogs.com/daaiwusehng/p/5386831.html
Copyright © 2020-2023  润新知