CGRectMake恢复到原始位置?

时间:2013-01-25 22:17:54

标签: xcode nslayoutconstraint cgrectmake

我使用以下内容将UIView从我在XIB / Storyboard上的原始位置移开:      - (无效)myMovingViewAction {

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

}

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

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

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

提前致谢! :)

1 个答案:

答案 0 :(得分:0)

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

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

}