gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:53:32 27 4
gpt4 key购买 nike

我当前在屏幕上有一个 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com