IOS 动画介绍

1、ios动画介绍

  ios动画实现有三种方式:

  (1)、UIView动画,最基本的动画使用方式,通过改变UIView的属性达到动画效果(渐隐/渐现)

  (2)、CATransition动画,用于两个视图过渡切换的动画,系统内置了集中动画效果,可以直接使用

  (3)、CAAnimation动画,ios核心动画,结合绘图可以实现多变的动画效果

2、UIView基本动画

IOS 动画介绍
 1 //标记动画块开始,设置动画id和context
 2 [UIView beginAnimations:@"testAnimation"context:@"test"];
 3 //以秒为单位设置动画持续时间
 4 [UIView setAnimationDuration:0.5];
 5 //定义动画加速和减速方式
 6 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
 7 //设置动画代
 8 [UIView setAnimationDelegate:self];
 9 //动画结束后回调方法
10 [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context)];
11 
12 //视图变化动作    
13 CGRect frame = self.myView.frame;
14 frame.origin.y = 400;
15 self.myView.frame = frame;
16 //动画结束
17 [UIView commitAnimations];
View Code

  block使用动画:

IOS 动画介绍
   [UIView animateWithDuration:0.7 animations:^{
        [UIView setAnimationRepeatCount:1000];
        
        self.myView.alpha = 0;
        
    } completion:^(BOOL finished){
        if (finished) {
    
        }
    }];
IOS 动画介绍

  动画类型:

    (1)、淡进淡出动画: 设置view.alpha为0.0 或1.0

    (2)、位置变换动画:更改view.frame实现

    (3)、缩放动画:

IOS 动画介绍
CGAffineTransform transform = view.transform;
//设置动画开始尺寸
view.transform = CGAffineTransform(transfrom,0.01,0.01);
[UIView beginAnimations:nil  context:nil]; 
[UIView setAnimationDuration:0.5];
//还原为原来的尺寸
view.transform = CGAffineTransform(transfrom,0.01,0.01); 

 //此行代码可以代替上面的代码,效果一样  

  self.myView.transform = CGAffineTransformIdentity;

[UIView commitAnimations];
IOS 动画介绍

    (4)、旋转动画:

IOS 动画介绍
view.transform = CGAffineTransformMakeRotation(3.14/2.0);
IOS 动画介绍

    (5)、设置代理,动画结束后调用相应的方法

IOS 动画介绍
[UIView setAnimationDelegate:self];    
[UIView setAnimationDidStopSelector:@selector(animationStop)];
[UIVeiw commitAnimations];    

//动画结束后调用
- (void)animationStop { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; CGRect frame = self.myView.frame; frame.origin.y = 54; self.myView.frame = frame; [UIView commitAnimations]; }
IOS 动画介绍

  (6)、视图切换的过渡动画

IOS 动画介绍
//注意动画是作用在父视图上的
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:parentView cache:YES];
    
[UIView commitAnimations];
//交换视图0和视图1的位置    
[parentView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
IOS 动画介绍

  (7)、自定义两个控制器之间的切换动画

IOS 动画介绍
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
  //视图切换动画作用于导航控制器的view上
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:YES];

    [UIView commitAnimations];
    
    UIViewController *viewContr = [[UIViewController alloc] init];
    [self.navigationController pushViewController:viewContr animated:NO];
IOS 动画介绍

  (8)、过渡动画的block使用方法

IOS 动画介绍
    [UIView transitionWithView:self.parentView duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
            [self.parentView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    } completion:NULL];
IOS 动画介绍

  options类型:

      IOS 动画介绍

2、CATransition动画的使用

  CATransition是对UIView进行更低层次的绘制,作用于UIView的Layer层,主要用于两个视图切换过渡时的动画

  (2.1)、导航控制器切换动画

IOS 动画介绍
    CATransition *animation = [CATransition animation];
    animation.duration = 0.6;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:@"easeInEaseOut"];
  //动画类型
    animation.type = kCATransitionPush;
  //动画子类型
    animation.subtype = kCATransitionFromLeft;
    [self.navigationController.view.layer addAnimation:animation forKey:@"test"];
    
    UIViewController *viewCtrl = [[UIViewController alloc] init];
    [self.navigationController pushViewController:viewCtrl animated:NO];
IOS 动画介绍

 

  动画类型:

    IOS 动画介绍  

3、UIImageView播放连续动画

IOS 动画介绍
imageView.animationImages = images;
imageView.animationDuration = 0.5f;
[imageView startAnimating];
IOS 动画介绍

4、开源动画库HMGLTransitions的使用

  基于openGL封装的开源动画库,使用时必须导入QuartzCore.framework和OpenGLES.framework

  动画效果继承于HMGLTransition:

  五种动画效果:

IOS 动画介绍
   //开门效果
    DoorsTransition *animation = [[DoorsTransition alloc] init];
    animation.transitionType = DoorsTransitionTypeClose;
    //3D效果
    Switch3DTransition *switch3D = [[Switch3DTransition alloc] init];
    switch3D.transitionType = Switch3DTransitionLeft;
    //
    ClothTransition *cloth = [[ClothTransition alloc] init];
    //翻页效果
    FlipTransition *flip = [[FlipTransition alloc] init];
    flip.transitionType = FlipTransitionLeft;
    //上下翻转效果
    RotateTransition *rotate = [[RotateTransition alloc] init];
IOS 动画介绍

 

  (1)、视图切换

IOS 动画介绍
  //创建动画类型对象
    Switch3DTransition *animation = [[Switch3DTransition alloc] init];

    //设置动画类型对象
    [[HMGLTransitionManager sharedTransitionManager] setTransition:animation];
    
    //设置动画需要添加的视图
    [[HMGLTransitionManager sharedTransitionManager] beginTransition:parentView];
    
    
    [[HMGLTransitionManager sharedTransitionManager] commitTransition];
    
    //切换视图
    [parentVIew exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
IOS 动画介绍

  (2)、模态视图弹出动画效果

IOS 动画介绍
  //定义动画对象
DoorsTransition *animation = [[DoorsTransition alloc] init]; [[HMGLTransitionManager sharedTransitionManager] setTransition:animation]; ModalViewController *viewCtrl = [[ModalViewController alloc] init];   //打开模态视图 [[HMGLTransitionManager sharedTransitionManager] presentModalViewController:viewCtrl onViewController:self];
IOS 动画介绍

  (3)、模态视图关闭的动画效果:

IOS 动画介绍
[[HMGLTransitionManager sharedTransitionManager] setTransition:animation];
[[HMGLTransitionManager sharedTransitionManager] dismissModalViewController:self];
IOS 动画介绍

IOS 动画介绍,布布扣,bubuko.com

IOS 动画介绍

上一篇:Android 内存溢出解决方案(OOM)


下一篇:使用AutoMapper实现Dto和Model的*转换