iOS UIView 转场动画

来源:互联网 发布:深圳小拨网络 skype 编辑:程序博客网 时间:2024/05/01 14:36

旋转的效果是作用在需要切换的视图所在的视图的父视图上


@interface LQTransformView()

@property(nonatomic,strong)UIView *view1;

@property(nonatomic,strong)UIView *view2;

@end


@implementation LQTransformView

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [superinitWithFrame:frame]) {

     

        [selfaddSubview:self.view1];

        

    }

    return self;

}


-(UIView *)view1{

    if (!_view1) {

        _view1 = [[UIViewalloc]initWithFrame:self.frame];

        _view1.backgroundColor = [UIColorredColor];

    }

    return _view1;

}

-(UIView *)view2{

    if (!_view2) {

        _view2 = [[UIViewalloc]initWithFrame:self.bounds];

        _view2.backgroundColor = [UIColorcyanColor];

    }

    return _view2;

}


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    if ([[selfsubviews]containsObject:self.view1]) {

          //相当于移除view1 添加View2


        [UIViewtransitionFromView:self.view1toView:self.view2duration:1 options:UIViewAnimationOptionTransitionFlipFromLeftcompletion:^(BOOL finished) {

        

        }];

    }else{

         //相当于移除view2 添加View1


        [UIViewtransitionFromView:self.view2toView:self.view1duration:1 options:UIViewAnimationOptionTransitionFlipFromLeftcompletion:^(BOOL finished) {

            

        }];

   

    }

}



@end


原创粉丝点击