0

我使用以下命令将 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 底部的原始位置。

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

提前致谢!:)

4

1 回答 1

0

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

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

}
于 2013-01-25T22:22:26.333 回答