iOS入门-46高级动画

概述

几种3D效果的动画,这里成为高级动画。高级动画的实现原理是利用OPENGL来完成的,具体的矩阵变化是图形学内容涉及到高数,这里不做展开说明,只是使用。

示例

要做的准备工作
  • 引入第三方动画库HMGLTransitions(用CocoaPods引入依赖,具体操作请参看前面的文章)
  • 添加三个核心库:CoreGraphics.framework、OpenGLES.framework、QuartzCore.gramework
    添加各个库依赖之后如下图:
    在这里插入图片描述

先看效果图

switch3d:
在这里插入图片描述
door
在这里插入图片描述

cloth
在这里插入图片描述

示例代码

ViewController.h
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    //一个父控件和两个字控件
    UIView* _parentView;
    UIImageView* _imgV01;
    UIImageView* _imgV02;
}

@end
ViewController.m
#import "ViewController.h"
//动画管理类
#import <HMGLTransitionManager.h>
//开门3d动画类型
#import <DoorsTransition.h>
//画布动画类型
#import <ClothTransition.h>
//3d变换动画类型
#import <Switch3DTransition.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _parentView = [UIView new];
    _parentView.frame = CGRectMake(50, 50, 300, 500);
    _parentView.backgroundColor = [UIColor yellowColor];
    
    
    _imgV01 = [UIImageView new];
    UIImage* image01 = [UIImage imageNamed:@"timg_1.jpg"];
    _imgV01 = [[UIImageView alloc] initWithImage:image01];
    _imgV01.frame = CGRectMake(0, 0, 300, 500);
    
    UIImage* image02 = [UIImage imageNamed:@"timg_2.jpg"];
    _imgV02 = [[UIImageView alloc] initWithImage:image02];
    _imgV02.frame = CGRectMake(0, 0, 300, 500);
    
    [_parentView addSubview:_imgV01];
    [self.view addSubview:_parentView];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //实例化动画管理器
    HMGLTransitionManager* manager = [HMGLTransitionManager sharedTransitionManager];
    
    //实例化3d动画对象(动画时间是固定的,不能我们手动调整)
    //Switch3DTransition* sAnim = [Switch3DTransition new];
    //设置动画的方向类型
    //[sAnim setTransitionType:Switch3DTransitionRight];
    
    //开门动画
    //DoorsTransition* dAnim = [DoorsTransition new];
    //类型:开门/关门
    //[dAnim setTransitionType:DoorsTransitionTypeOpen];
    
    //画布类型动画
    ClothTransition* cAnim = [ClothTransition new];
    
    //动画添加到动画管理器
    [manager setTransition:cAnim];
    //将目标view添加到动画管理器中,注意这里是给父控件添加动画
    [manager beginTransition:_parentView];
    
    static BOOL isFirst = YES;
    if (isFirst) {
        //让第一个view消失
        [_imgV01 removeFromSuperview];
        //设置第二个view的位置大小为第一个view的
        _imgV02.frame = _imgV01.frame;
        //将第二个view添加到父控件中
        [_parentView addSubview:_imgV02];
    }else{
        [_imgV02 removeFromSuperview];
        
        _imgV01.frame = _imgV02.frame;
        
        [_parentView addSubview:_imgV01];
    }
    isFirst = !isFirst;
    
    //执行动画
    [manager commitTransition];
}

@end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值