爱程序网

核心动画——转场动画

来源: 阅读:

转场动画:CATransition

属性介绍:

    ①type:转场动画的动画效果

         kCATransitionFade   交叉淡化过渡

         kCATransitionMoveIn 新视图移到旧视图上面

         kCATransitionPush   新视图把旧视图推出去

         kCATransitionReveal 将旧视图移开,显示下面的新视图

     转场动画的动画效果 私有api

       pageCurl            向上翻一页

       pageUnCurl          向下翻一页

       rippleEffect        滴水效果

       suckEffect          收缩效果 如一块布被抽走

       cube                立方体效果

       oglFlip             上下翻转效果

  ②subtype:转场动画的效果方向

         kCATransitionFromRight

         kCATransitionFromLeft

         kCATransitionFromTop

         kCATransitionFromBottom

    ③startProgress 开始进度 (0,1)

    ④endProgress 结束进度

以上就是关于转场动画的介绍

具体代码如下:

首先在Main.storyBoard里面创建一个UIImageView,设置image、contentModel,点击右键不放将他拖到工程@interface里面。

#import "ViewController.h"

@interface ViewController ()
{
    //图片的标记
    int index;
}
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (IBAction)leftSwipe:(id)sender {
    [self changImageWithDirection:YES];
    
    
}

- (IBAction)rightSwipe:(id)sender {
    [self changImageWithDirection:NO];
}

- (void)changImageWithDirection:(BOOL)direction{
   
    CATransition *animation = [CATransition animation];
    animation.duration = 2;
    
    if (direction != YES) {
        index --;
        NSLog(@"向右");
        animation.type = @"oglFlip";//上下翻转效果
        animation.subtype = kCATransitionFromLeft;//方向向左
        
    }else{
        index ++;
        NSLog(@"向左");
        animation.type = @"cube";//立方体效果
        animation.subtype = kCATransitionFromRight;

    }
    
    if (index<0) {
        index = 6;
    }
    if (index>6) {
        index = 0;
    }
    
    self.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"社区%d.jpg",index+1]];
    [self.imageView.layer addAnimation:animation forKey:@""];
}

@end

效果如下:

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助