欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

iOS:动画,ios动画

来源: 开发者 投稿于  被查看 49615 次 评论:218

iOS:动画,ios动画


 1、UIView Animation

  1-1)、原始的,非Block。

//动画名、内容
[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)、原始的

//创建
CATransition *animation = [CATransition animation];
//动画时间
animation.duration = 1.5;
//动画类型
//    kCATransitionFade           //淡入
//    kCATransitionMoveIn         //覆盖
//    kCATransitionPush           //推
//    kCATransitionReveal         //掀起,相对覆盖
//    @"cube"                     //立方体(某宝的AR切换)
//    @"suckEffect"               //吮吸
//    @"oglFlip"                  //翻转(某信,好友历史说说,查看详情)
//    @"rippleEffect"             //波纹
//    @"pageCurl"                 //日历上翻
//    @"pageUnCurl"               //日历下盖
//    @"cameraIrisHollowOpen"     //相机打开
//    @"cameraIrisHollowClose"    //相机关闭
animation.type = @"cube";
//动画方向
//    kCATransitionFromRight      //从右边
//    kCATransitionFromLeft       //从左边
//    kCATransitionFromTop        //从上面
//    kCATransitionFromBottom     //从下面
animation.subtype = kCATransitionFromLeft;
//动画速度(慢入、慢出)
//    kCAMediaTimingFunctionLinear        //匀速
//    kCAMediaTimingFunctionEaseIn        //慢入
//    kCAMediaTimingFunctionEaseOut       //慢出
//    kCAMediaTimingFunctionEaseInEaseOut //慢入慢出
//    kCAMediaTimingFunctionDefault       //匀速,不过有点快
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
//代理
//- (void)animationDidStart:(CAAnimation *)anim;
//- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;
animation.delegate = self;

//1、添加动画到导航栏
[self.navigationController.view.layer addAnimation:animation forKey:@"animation"];
[self.navigationController pushViewController:vc animated:NO];

//2、添加动画到普通的View
[bgView.layer addAnimation:animation forKey:@"animation"];
//把最上面的View放到最底层,一般转场可能就2层相互转换,也可用exchangeSubviewAtIndex:withSubviewAtIndex:
[bgView sendSubviewToBack:[[bgView subviews] lastObject]];

  2-2)、封装过的,简洁,用UIView Animation,View的方法,非Layer

//参数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]];
}];

  2-3)、VC自带的模态视图转场动画

//设置模态视图的转场效果(如X信,朋友的历史单条说说,点击查看详细)。
second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//推
[self presentViewController:second animated:YES completion:^{
}];

  

  

用户评论