zoukankan      html  css  js  c++  java
  • ios 动画系列之一------简单动画的实现

    实现ios动画,主要有两种方法:UIView层面上的、使用CATransition。

    一、UIView层面上的

    [UIView beginAnimations:@"animation" context:nil];
    [UIView setAnimationDuration:1.0f];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
    //交换本视图控制器中2个view位置
    [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:1];
    [UIView setAnimationDidStopSelector:@selector(animationFinish:)];
    [UIView commitAnimations];

    以beginAnimations:开始,以commitAnimations结束,关于动画的一切设置都写在这两个方法之间,不然无效。

    二、使用CATransition

    CATransition *transition = [CATransition animation];
    transition.duration = 2.0f;
    transition.type = @"cube";
    transition.subtype = kCATransitionFromLeft;
    [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];    
    [self.view.layer addAnimation:transition forKey:@"animation"];

    这里有两个属性要注意,type,Subtype,一般都是把这两个属性组合使用,我们来看一下官方对这两个属性的解释。
    1、@property(copy) NSString *type;

    type是这个transition的名字,当前合法的transition类型包括:`fade', `moveIn', `push' and `reveal',默认是`fade'。

    它公开的类型可以有:淡化、移入、推挤、覆盖

    NSString * const kCATransitionFade;
    NSString * const kCATransitionMoveIn;
    NSString * const kCATransitionPush;
    NSString * const kCATransitionReveal;

    2、@property(copy) NSString *subtype;

    subtype是这个transition可选的类型,比如,用来区分这个transition的方向,合法的值有`fromLeft', `fromRight', `fromTop' and  * `fromBottom'.

    它公开的类型可以有:

    NSString * const kCATransitionFromRight;
    NSString * const kCATransitionFromLeft;
    NSString * const kCATransitionFromTop;
    NSString * const kCATransitionFromBottom;

    3、本来没什么疑问,看到这个说明后,反而觉得奇怪,如果type只有这么几个类型,那cube、page等都是在哪实现的了?

      cube等效果都不是它公开的方法,而是它提供的私有类型。

    animation.type = @"cube" ;  //立方体翻转
    animation.type = @"suckEffect";   //收缩效果,如一块布被抽走  
    animation.type = @"oglFlip";//上下翻转效果,不管subType is "fromLeft" or "fromRight",official只有一种效果   
    animation.type = @"rippleEffect";   //滴水效果
    animation.type = @"pageCurl";   //向上翻一页
    animation.type = @"pageUnCurl"  //向下翻一页
    animation.type = @"cameraIrisHollowOpen ";  //类似于ios的相机打开时的效果
    animation.type = @"cameraIrisHollowClose ";  //类似于ios的相机关闭时的效果

         这些私有类型尽量少用。

    4、CATransition的startProgress  endProgress属性
    这两个属性用来控制动画开始的点和结束的点,值在0.0--0.1之间。这个控制开始和结束的点,意思就是让动画不是从起点开始,而是从某一点开始,到某一点就停止动画效果,不是画面停止,而是动画效果停止。感觉没说清楚,这个自己试一下就知道了。

     我们将在下一节详细介绍ios动画的各个属性设置。

  • 相关阅读:
    Oracle导出导入表空间创建
    ASP.NET 缓存 SqlCacheDependency 监视数据库表变化 让缓存更新的更及时更提高节能
    Silverlight在添加WCF服务引用时报错
    springboot中如何动态更换 配置文件 spring.profiles.active
    maven之根据profile动态切换resource
    java synchronized 关键字的锁升级过程
    子类中的方法和父类同名,但是参数不同,是重写(overload)不是覆盖(override)
    Java的协变(extends)和逆变(super),说白了都是子类的实例赋值给父类的变量
    Mybatis缓存
    [转]Spring MVC之 @PathVariable @CookieValue@RequestParam @RequestBody @RequestHeader@SessionAttributes, @ModelAttribute
  • 原文地址:https://www.cnblogs.com/wyqfighting/p/3204844.html
Copyright © 2011-2022 走看看