国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS基于CATransition實現翻頁、旋轉等動畫效果

2020-07-26 02:20:23
字體:
來源:轉載
供稿:網友

基于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"  //關鏡頭效果

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 瓦房店市| 桐梓县| 长武县| 高密市| 双峰县| 昌图县| 景德镇市| 聊城市| 历史| 响水县| 洛南县| 临高县| 柯坪县| 临洮县| 柘城县| 汽车| 金昌市| 温泉县| 平山县| 浠水县| 沈丘县| 巴林左旗| 芒康县| 兴化市| 准格尔旗| 华宁县| 马尔康县| 中方县| 蓝田县| 阿勒泰市| 长沙市| 湟源县| 惠州市| 霍林郭勒市| 绥阳县| 英山县| 青州市| 临沂市| 黎川县| 大埔县| 阳朔县|