900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 动画特效之转场动画

动画特效之转场动画

时间:2023-02-02 11:28:46

相关推荐

动画特效之转场动画

首先新建一个类,然后引入到项目中,在ViewController中导入新建的类,实现方法跳转到新建的类里面,可以看到相应的效果:

#import "ViewController.h"typedef enum Direction{Right = 0,Left,Top,Down,}Direction;@interface ViewController (){NSArray *ImageList;UIImageView *showImage;int index;}@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];/*kCATransitionFade 交叉淡化过渡kCATransitionMoveIn 新视图移到旧视图上面kCATransitionPush 新视图把旧视图推出去kCATransitionReveal 将旧视图移开,显示下面的新视图私有api 不建议使用 苹果不提供维护 并且有可能app审核不通过pageCurl 向上翻一页pageUnCurl向下翻一页rippleEffect 滴水效果suckEffect收缩效果 如一块布被抽走cube立方体效果oglFlip 上下翻转效果*/ImageList = @[@"1.jpg",@"2.jpg",@"3",@"4"];showImage = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];showImage.userInteractionEnabled = YES;showImage.image = [UIImage imageNamed:ImageList[0]];[self.view addSubview:showImage];UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(rightAction:)];swipe.direction = UISwipeGestureRecognizerDirectionRight;[showImage addGestureRecognizer:swipe];UISwipeGestureRecognizer *left = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftAction:)];left.direction = UISwipeGestureRecognizerDirectionLeft;[showImage addGestureRecognizer:left];UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(LongAction:)];[showImage addGestureRecognizer:longTap];}#pragma mark 长按手势实现方法- (void)LongAction:(UILongPressGestureRecognizer *)longTap{if (longTap.state == UIGestureRecognizerStateBegan) {Add_ViewController *next = [[Add_ViewController alloc]init];CATransition *transition = [CATransition animation];transition.type = @"suckEffect";transition.duration = 1;transition.subtype = kCATransitionFromLeft;[self.navigationController.view.layer addAnimation:transition forKey:nil];// 如果使用自定义的转场动画 必须禁用系统的动画[self.navigationController pushViewController:next animated:NO];}}#pragma mark 轻烧手势实现方法- (void)leftAction:(UISwipeGestureRecognizer *)left{[self ChangeImageWithDirection:Left];}- (void)rightAction:(UISwipeGestureRecognizer *)weipe{[self ChangeImageWithDirection:Right];}#pragma mark 判断滑动的方向- (void)ChangeImageWithDirection:(Direction)direction{// 通过滑动的方向判断是自加还是自减index = direction == Right ? [self selfMinus]:[self selfAdd];// 判断左右滑动的时候不同的效果CATransition *transition = [CATransition animation];transition.duration = 3;transition.type = direction == Right ?@"cube":@"rippleEffect";[showImage.layer addAnimation:transition forKey:nil];showImage.image = [UIImage imageNamed:ImageList[index]];}#pragma mark 向右滑动的时候自减- (int)selfMinus{index --;return index <= 0 ? (int)ImageList.count-1:index;}#pragma mark 向左滑动的时候自加- (int)selfAdd{index ++;// 如果超出数组元素个数的范围 就返回0// 没有超出就是自加后的值return index >= ImageList.count ? 0:index;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。