这篇文章将为大家详细讲解有关iOS中怎么利用CATransition实现翻页旋转效果,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
#import <UIKit/UIKit.h>@interface ViewController : UIViewController@end#import "ViewController.h"//获得屏幕的宽高#define mainW [UIScreen mainScreen].bounds.size.width#define mainH [UIScreen mainScreen].bounds.size.height@interface ViewController ()@property (nonatomic, strong) NSArray *typeArray;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor greenColor]; //创建控件 [self creatControl]; _typeArray = @[kCATransitionFade, kCATransitionPush, kCATransitionMoveIn, kCATransitionReveal, @"cube", @"suckEffect", @"oglFlip", @"rippleEffect", @"pageCurl", @"pageUnCurl", @"cameraIrisHollowOpen", @"cameraIrisHollowClose"];}- (void)creatControl{ NSArray *titleArray = @[@"淡化效果", @"推进效果", @"滑入效果", @"滑出效果", @"立方体效果", @"吮吸效果", @"翻转效果", @"波纹效果", @"翻页效果", @"反翻页效果", @"开镜头效果", @"关镜头效果"]; for (int i = 0; i < titleArray.count; i++) { CGFloat X = i % 2 == 0 ? mainW * 0.1 : mainW * 0.6; CGFloat Y = 64 + i / 2 * mainW * 0.15; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(X, Y, mainW * 0.3, mainW * 0.1)]; btn.tag = i; [btn setBackgroundColor:[UIColor colorWithRed:0.6f green:0.7f blue:0.6f alpha:0.7f]]; [btn setTitle:titleArray[i] forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnOnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; }}- (void)btnOnClick:(UIButton *)btn{ static int i = 0; i = i == 0 ? 1 : 0; self.view.backgroundColor = i == 0 ? [UIColor greenColor] : [UIColor yellowColor]; //创建CATransition对象 CATransition *animation = [CATransition animation]; //设置时间 animation.duration = 1.0f; //设置类型 animation.type = _typeArray[btn.tag]; //设置方向 animation.subtype = kCATransitionFromRight; //设置运动速度变化 animation.timingFunction = UIViewAnimationOptionCurveEaseInOut; [self.view.layer addAnimation:animation forKey:@"animation"];}@end
CATransition.type动画类型:
kCATransitionFade //淡化效果kCATransitionPush //推进效果kCATransitionMoveIn //滑入效果kCATransitionReveal //滑出效果@"cube" //立方体效果@"suckEffect" //吮吸效果@"oglFlip" //翻转效果@"rippleEffect" //波纹效果@"pageCurl" //翻页效果@"pageUnCurl" //反翻页效果@"cameraIrisHollowOpen" //开镜头效果@"cameraIrisHollowClose" //关镜头效果
关于iOS中怎么利用CATransition实现翻页旋转效果就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。