景色是“跳跃”的。当我将它添加到 UIWindow 作为子视图(通过 rootViewController 属性)并进行翻转时
我有两个简单的 UIViewController,它们的视图为 320 x 460,带有状态栏。我在 AppDelegate 中
self.window.rootViewController = [[[SimpleController alloc] init] autorelease];
[self.window makeKeyAndVisible];
的 SimpleController 中做了一个按钮,该按钮执行
- (IBAction) switchToVerySimpleController
{
[UIView transitionWithView: [[UIApplication sharedApplication] keyWindow]
duration: 0.5
options: UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ [[UIApplication sharedApplication] keyWindow].rootViewController = [[[VerySimpleController alloc] init] autorelease]; }
completion: NULL];
}
新视图(VerySimpleController.view)填充蓝色。动画结束后,新视图会在底部显示一个微小的白色条纹(状态栏大小),然后向下跳到位。为什么会发生这种情况以及如何避免这种情况?我想这应该归咎于状态栏,我尝试在 IB 中为两个视图设置 statusBar = Unspecified,但这没有帮助。
更新: 当我从一开始就隐藏状态栏(通过 .info 文件中的设置)时,不会发生视图调整。但仍然...我需要显示状态栏并且我需要该动画正常工作。
I have two simple UIViewControllers, their views are 320 x 460 with status bars. I do in AppDelegate
self.window.rootViewController = [[[SimpleController alloc] init] autorelease];
[self.window makeKeyAndVisible];
In SimpleController I have a button that does
- (IBAction) switchToVerySimpleController
{
[UIView transitionWithView: [[UIApplication sharedApplication] keyWindow]
duration: 0.5
options: UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ [[UIApplication sharedApplication] keyWindow].rootViewController = [[[VerySimpleController alloc] init] autorelease]; }
completion: NULL];
}
The new view (VerySimpleController.view) is filled with a blue color. After animation new view is shown with a tiny white stripe (with the size of a status bar) at the bottom and then it jumps down into place. Why is it happening and how to avoid that? I suppose its status bar to blame, and I tried to set statusBar = Unspecified in IB for both views, but it doesn't help.
UPDATE:
When I hide statusBar (thru setting in .info file) from the start, no view adjustment occurs. But still... I need to show statusBar and I need that animation working properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当 rootViewController 分配给窗口时, a如果存在状态栏,新框架将被分配到 rootViewController 的视图。这样 rootViewController 的
视图不会隐藏在状态栏下方。
由于您在动画块内设置窗口的 rootViewController,因此新的帧分配也会进行动画处理。
为了不显示跳转,您可以在动画之前设置 rootViewController 视图的框架,如下所示:
When a rootViewController is assigned to a window, a new frame is assigned to the rootViewController's view if a status bar is present. This is so that the rootViewController's
view won't be hidden under the status bar.
Since you're setting the window's rootViewController inside the animation block, the new frame assignment gets animated as well.
To not show the jump you might set the frame of the rootViewController's view before the animation with something like this:
看来这个问题有时仍然会发生,这可能是一个错误。
为了避免这种“跳转”,请将此代码添加到需要显示的视图控制器的
viewWillAppear
方法中:swift
Objective-c
现在,转换将在没有“跳转”的情况下完成。
It seems that this issue still sometimes happen and it's probably a bug.
To avoid this 'jump' add this code to the
viewWillAppear
method of the view controller which needs to be shown:swift
objective-c
The transition will now finish without the 'jump'.