版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaoxingaiwo/article/details/81660913
先来看下效果
![]()
主控制器的.h文件:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
//动画切换的容器父视图
UIView *_parentView;
//图像视图1
UIImageView *_imageView;
//图像视图2
UIImageView *_imageView2;
}
@end
主控制器的.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];
_parentView=[[UIView alloc]init];
_parentView.frame=CGRectMake(40, 80, 260, 380);
[self.view addSubview:_parentView];
_parentView.backgroundColor=[UIColor orangeColor];
//创建视图对象
_imageView=[[UIImageView alloc]init];
_imageView.frame=CGRectMake(0, 0, 260, 380);
_imageView.image=[UIImage imageNamed:@"super_light_80"];
_imageView2=[[UIImageView alloc]init];
_imageView2.frame=CGRectMake(0, 0, 260, 380);
_imageView2.image=[UIImage imageNamed:@"super_task_80"];
[_parentView addSubview:_imageView];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self startAnim];
}
-(void)startAnim
{
//创建动画管理对象
HMGLTransitionManager *manager=[HMGLTransitionManager sharedTransitionManager];
//动画变换对象
Switch3DTransition *sAnim=[[Switch3DTransition alloc]init];
//设置动画的方向类型
[sAnim setTransitionType:Switch3DTransitionLeft];
//动画类型2-开门
DoorsTransition *door=[[DoorsTransition alloc]init];
[door setTransitionType:DoorsTransitionTypeClose];
//动画类型3-画布
ClothTransition *cloth=[[ClothTransition alloc]init];
//设置动画类型
[manager setTransition:cloth];
//设置动画视图的容器对象
[manager beginTransition:_parentView];
static BOOL flage=YES;
if (flage) {
[_imageView removeFromSuperview];
_imageView2.frame=_imageView.frame;
[_parentView addSubview:_imageView2];
}else{
[_imageView2 removeFromSuperview];
_imageView.frame=_imageView2.frame;
[_parentView addSubview:_imageView];
}
flage=!flage;
//提交动画运行效果
[manager commitTransition];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
下面是必须导入的三个库文件