ios - 动画似乎不起作用 - 在 [self dismiss ViewController] 上将 View 从一个位置移动到另一个位置

标签 ios uiviewanimation

我当前在屏幕上有一个 View ,我想在动画期间将其移出屏幕。它的当前位置是:CGRectMake(0, 168, 320, 50);我想把它移到 y 位置 218。

这是我的代码:

 [UIView beginAnimations:Nil context:NULL];
 [UIView setAnimationDuration:0.3];
 self.optionsView.frame = CGRectMake(0, 218, 320, 50);
 [UIView commitAnimations];

提前致谢。什么都没有发生, View 没有移出屏幕。

编辑:当应用程序启动时, View 不在屏幕上,然后我调用:
[UIView beginAnimations:Nil context:NULL];
 [UIView setAnimationDuration:0.3];
 self.optionsView.frame = CGRectMake(0, 168, 320, 50);
 [UIView commitAnimations];

将 View 带入主视图。我遇到的问题是使 View 再次退出屏幕:
 [UIView beginAnimations:Nil context:NULL];
 [UIView setAnimationDuration:0.3];
 self.optionsView.frame = CGRectMake(0, 218, 320, 50);
 [UIView commitAnimations];

必须注意的是,为了让 View 在应用启动时关闭屏幕,我调用:
-(void) viewDidLayoutSubviews{
    self.optionsView.frame = CGRectMake(0, 218, 320, 50);
}

更新:我也在使用相机,我认为关闭相机会影响布局

最佳答案

我已经为 View 的位置设置了动画,如下所示:

// 'frame' variable previously declared
// 'completion' block previously declared

[UIView animateWithDuration:0.3f
                      delay:0.0f
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     [_someView setFrame:frame];
                 }
                 completion:^(BOOL finished){
                     if (completion) {
                         completion();
                     }
                 }];

你试过这样吗?

正如 Martin Koles 所说,首选基于 block 的方法来查看动画。以下是 UIView 的引用文档:

Use of the methods in this section is discouraged in iOS 4 and later. Use the block-based animation methods instead.



https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/UIView/UIView.html

关于ios - 动画似乎不起作用 - 在 [self dismiss ViewController] 上将 View 从一个位置移动到另一个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22534173/

相关文章:

ios - UIView 隐藏/显示动画

ios - 带有按钮的弹出框/工具提示,就像 iOS 自动更正一样

ios - 动画移回原始位置后未调用UIView动画

ios - 将图像和标签保存并检索到下一个 View 。代码

iOS:MKMapView 在加载时旋转

ios - UIView动画中初始调整UITextView帧大小时跳转

ios - 显示和隐藏 UIView

ios - lldb 'step into' 无法跳转到 Xcode7 上的函数调用?

ios - Swift 3 - UTC to time ago 标签,考虑 12h/24h 设备时间变化

ios - 如何强制一个 View Controller 以横向显示而另一个始终保持纵向