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

 

posted on 2016-04-13 13:44  大爱无声  阅读(1155)  评论(0编辑  收藏  举报

导航