美文网首页
iOS UIView的转场动画

iOS UIView的转场动画

作者: 霸_霸霸 | 来源:发表于2018-09-07 11:10 被阅读10次
    transitionGif.gif

    属性

    //view1
    @property (nonatomic, strong)UIView *view1;
    //view2
    @property (nonatomic, strong)UIView *view2;
    //view3 作为容器, 将view1和view2添加到view3中
    @property (nonatomic, strong)UIView *view3;
    

    伪代码

    _view3 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 100)];
    [self.view addSubview:view3];
    view1.frame = CGRectMake(0, 0, 200, 100);
    view2.frame = CGRectMake(0, 0, 200, 100);
    [self.view3 addSubview:view1];
    [self.view3 addSubview:view2];
    
    // 添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
    [self.view3 addGestureRecognizer:tap];
    
    - (void)tapClick:(UITapGestureRecognizer *)tap{
        if (i % 2 != 0) {
            [UIView transitionFromView:self.view1 toView:self.view2 duration:1.0 options:UIViewAnimationOptionTransitionFlipFromTop completion:nil];
        }else{
            [UIView transitionFromView:self.view2 toView:self.view1 duration:1.0 options:UIViewAnimationOptionTransitionFlipFromBottom completion:nil];
        }
        i++;
    }
    

    动画的关键在于options, 上面采用的是UIViewAnimationOptionTransitionFlipFromTopUIViewAnimationOptionTransitionFlipFromBottom

    • 如果我们采用UIViewAnimationOptionTransitionFlipFromLeftUIViewAnimationOptionTransitionFlipFromRight

      transitionGif1.gif
    • UIViewAnimationOptionTransitionCurlUpUIViewAnimationOptionTransitionCurlDown

      transitionGif2.gif
    • UIViewAnimationOptionTransitionCrossDissolve

      transitionGif3.gif

    相关文章

      网友评论

          本文标题:iOS UIView的转场动画

          本文链接:https://www.haomeiwen.com/subject/rtaqgftx.html