【问题标题】:CGRectMake Revert back to original position?CGRectMake 恢复到原来的位置?
【发布时间】:2013-01-25 22:17:53
【问题描述】:

我正在使用以下命令将 UIView 从其原始位置移动到我的 XIB/Storyboard 上: -(void)myMovingViewAction{

[UIView animateWithDuration:.15
                 animations:^{
                     [theView setFrame:CGRectMake(0, 40, theView.frame.size.width, theView.frame.size.height)];
                 }
 ];

}

我遇到的问题是将 UIView 恢复到其在我的 Storyboard UIViewController/XIB 上布置的原始位置。

我知道我可以使用与上面相同的代码,其中包含原始坐标,但是这些坐标在不同的设备上是不同的。在这个例子中,约束让我的 UIView 紧贴我的 UIViewController 底部的原始位置。

有没有办法可以将此视图发送回“默认”位置?

提前致谢! :)

【问题讨论】:

    标签: xcode nslayoutconstraint cgrectmake


    【解决方案1】:

    创建一个 CGRect 类型的实例 var theFrame,将其设置为 viewDidAppear 上的 theView.frame。当你想把它移回原来的位置时,你可以这样做

    [UIView animateWithDuration:.15
                     animations:^{
                         [theView setFrame:theFrame];
                     }
     ];
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多