【问题标题】:How To Animate UIView Frame with ViewWillLayoutSubview如何使用 ViewWillLayoutSubview 为 UIView 框架设置动画
【发布时间】:2018-02-04 08:40:50
【问题描述】:

我以编程方式创建了两个 UIView,并在 ViewWillLayoutSubview 函数中设置了它的框架,现在我想创建一个交换动画,以便每个视图通过单击动画交换彼此的位置。为了获得这个动画,我必须在动画中交换它的帧,但同时调用 ViewWillLayoutSubview 将帧设置为初始位置。

如何使用 ViewWillLayoutSubview 让我的 UIView 与动画交换?

我没有使用任何类型的约束或 xib 或故事板。整个屏幕都是程序化设计的。

提前致谢。

【问题讨论】:

    标签: ios objective-c animation uiview


    【解决方案1】:
    -(void)viewWillLayoutSubviews
    {
        if(Once)
       {
           // create 2 views here
    
          once = NO;
       }
    
    }
    

    将此代码放入按钮点击

    CGRect view2Frame = self.view2.frame;
    
    [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveLinear  animations:^{
        //code with animation
    
    
          self.view2.frame = self.view1.frame;
    
          self.view1.frame = view2Frame;
    
    
    } completion:^(BOOL finished) {
        //code for completion
    }];
    

    【讨论】:

    • UIview动画块应该写什么?
    猜你喜欢
    • 1970-01-01
    • 2017-06-25
    • 2018-01-03
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    相关资源
    最近更新 更多