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