iOS基于CATransition实现翻页、旋转等动画效果

2022-10-21,,,

这篇文章主要为大家详细介绍了iOS基于CATransition实现翻页旋转等动画效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

基于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实现抖音点赞动画效果
  • iOS实现点赞动画特效
  • iOS仿AirPods弹出动画
  • iOS自定义转场动画的几种情况
  • iOS自定义UIButton点击动画特效
  • iOS实现转场动画的3种方法示例
  • iOS实现数字倍数动画效果
  • iOS如何优雅地实现序列动画详解
  • iOS仿抖音视频加载动画效果的实现方法
  • iOS仿微博导航栏动画(CoreGraphics)的实现方法
  • 详解 iOS 系统中的视图动画

《iOS基于CATransition实现翻页、旋转等动画效果.doc》

下载本文的Word格式文档,以方便收藏与打印。