UIView 动画
UIView封装的动画有三类,下面是三个category 的名字:
UIViewAnimationWithBlocks
UIViewKeyframeAnimations
UIViewAnimation
1,UIViewAnimationWithBlocks
上面这个动画用的是 transitionWithView。 主要用途是UIView的切换。
[UIView transitionWithView:self.myView1 duration:1 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionTransitionCurlUp animations:^{ self.myView1.hidden = YES; } completion:^(BOOL finished) { }];
这个就是向上翻页的效果。
2,UIViewKeyframeAnimations
上面的动画用的是animateKeyframesWithDuration,关键帧动画。
[UIView animateKeyframesWithDuration:2 delay:0 options:UIViewKeyframeAnimationOptionBeginFromCurrentState animations:^{ [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.2 animations:^{ weafSelf.myImageView.transform = CGAffineTransformMakeRotation(45); weafSelf.myImageView.center = CGPointMake(200, 200); }]; [UIView addKeyframeWithRelativeStartTime:0.1 relativeDuration:0.2 animations:^{ weafSelf.myImageView.transform = CGAffineTransformIdentity; weafSelf.myImageView.center = CGPointMake(100, 150); }]; } completion:nil];
addKeyframeWithRelativeStartTime是在关键帧动画里面的,每一帧。注意里面的时间参数和持续时间参数都是百分比,0.1代表的是十分之一的持续时间。
3,UIViewAnimation
上面的动画用的是下面的代码。
[UIView beginAnimations:@"test " context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationWillStartSelector:@selector(onStart)]; [UIView setAnimationDelegate:self]; self.myImageView.center = CGPointMake(self.myImageView.center.x + 20, self.myImageView.center.y + 20); [UIView commitAnimations];
在begin 和 commit 之间的代码,相当于blocks里面。
代码地址:
https://github.com/loyinglin/LearnViewAnimations