1、UIView Animation
1-1)、旧的。
class="brush:objc;gutter:true;">//动画名、内容
[UIView beginAnimations:@"id100" context:@"animation1"];
//时长2秒
[UIView setAnimationDuration:2.0];
//开始缓慢,不会匀速
// UIViewAnimationCurveEaseInOut, // 慢入、慢出
// UIViewAnimationCurveEaseIn, // 慢入
// UIViewAnimationCurveEaseOut, // 慢出
// UIViewAnimationCurveLinear, // 匀速
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//设置代理
[UIView setAnimationDelegate:self];
//动画将要开始SEL
[UIView setAnimationWillStartSelector:@selector(animationWillStart:context:)];
//动画将要结束SEL
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
//提交动画
[UIView commitAnimations];
//签代理后,才能实现SEL的方法(方法名随意,参数个数也随意,分别少于2/3个的时候,只收到前面几个参数,多于它的参数,后面参数空,有用过C的回调函数,应该比较熟悉)
//开始动画时的方法
-(void)animationWillStart:(NSString *)animationID context:(void *)context
{
NSLog(@"动画开始");
}
//结束动画时的方法
-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
//可以判断ID,做连续动画
NSLog(@"动画结束”);
}
//自己取名
-(void)theAnimationStop:(NSString *)animationID thecontext:(void *)theContext context:(void *)context2
{
NSLog(@"%@,%@,%@",animationID,theContext,context2);
}
1-2)、Block
//嵌套,做连续动画
[UIView animateWithDuration:2.0 animations:^{
self.cyanVIew.frame = CGRectMake(100, 400, 100, 100);
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.0 animations:^{
self.cyanVIew.frame = CGRectMake(100, 100, 100, 100);
}];
}];
2、Transition
2-1)、转场动画
//参数cache,YES为截图后再转场,减轻系统负担,动画更流畅,NO为一起动画,如需要边转场边动画的效果
// UIViewAnimationTransitionNone,
// UIViewAnimationTransitionFlipFromLeft, //左边下翻效果(X信,好友历史说说,查看详情)
// UIViewAnimationTransitionFlipFromRight, //右边下翻效果
// UIViewAnimationTransitionCurlUp, //上翻日历效果
// UIViewAnimationTransitionCurlDown, //下盖日历效果
//1、导航栏转场
[UIView animateWithDuration:2.0 animations:^{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:YES];
[self.navigationController pushViewController:vc animated:NO];
}];
//2、普通View转场,把当前View放在最底层,最好大小全相同,不然动画效果很尴尬
[UIView animateWithDuration:2.0 animations:^{
//转场动画
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:bgView cache:YES];
//最上面的View放到最下面
[bgView sendSubviewToBack:[[bgView subviews] lastObject]];
}];