旋转的效果是作用在需要切换的视图所在的视图的父视图上
@interface LQTransformView()
@property(nonatomic,strong)UIView *view1;
@property(nonatomic,strong)UIView *view2;
@end
@implementation LQTransformView
-(instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self addSubview:self.view1];
}
return self;
}
-(UIView *)view1{
if (!_view1) {
_view1 = [[UIView alloc]initWithFrame:self.frame];
_view1.backgroundColor = [UIColor redColor];
}
return _view1;
}
-(UIView *)view2{
if (!_view2) {
_view2 = [[UIView alloc]initWithFrame:self.bounds];
_view2.backgroundColor = [UIColor cyanColor];
}
return _view2;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
if ([[self subviews]containsObject:self.view1]) {
//相当于移除view1 添加View2
[UIView transitionFromView:self.view1 toView:self.view2 duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
}];
}else{
//相当于移除view2 添加View1
[UIView transitionFromView:self.view2 toView:self.view1 duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
}];
}
}
@end