iOS基于CATransition实现翻页、旋转等动画效果
程序员文章站
2023-11-30 08:12:28
基于catransition实现翻页、旋转、淡化、推进、滑入滑出、立方体、吮吸、波纹等动画效果。
首先看一下效果图:
下面贴上代码:
#import &l...
基于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" //关镜头效果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。