我可以在没有黑条的情况下旋转 UIView 吗? [英] Can I rotate a UIView without the black bars?

查看:21
本文介绍了我可以在没有黑条的情况下旋转 UIView 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIView,它占据了 iphone 上的整个窗口.当它旋转到横向时,边缘会出现小黑条,直到它卡入到位,正如我所期望的那样.

I have a UIView that takes up the entirety of the window on the iphone. When it rotates to landscape, the edges get the little black bars until it snaps into place, as i would expect.

我想让那个 uiview 比屏幕大,这样旋转它就不会显示那些黑条,而是显示通常在屏幕外的视图部分.我试过增加视图的框架和边界,但这似乎不起作用.

I want to make that uiview bigger than the screen, so that rotating it doesn't show those black bars but shows the parts of the view that are normally offscreen. I've tried increasing the frame and bounds of the view, but that doesn't seem to do the trick.

有人成功过吗?

推荐答案

你需要做两件事来实现这一点.

You need to do two things to make this happen.

首先,窗口的根视图控制器将始终将其视图调整为窗口的大小.所以你的大视图需要是根视图控制器视图的子视图(以防止它被缩小),并且你的根视图控制器的视图需要将 clipsToBounds 设置为 NO.事实上,大视图的所有祖先都需要将 clipsToBounds 设置为 NO.

First, the window's root view controller will always resize its view to the size of the window. So your big view needs to be a subview of the root view controller's view (to keep it from being resized down), and your root view controller's view needs to have clipsToBounds set to NO. In fact all ancestors of the big view need to have clipsToBounds set to NO.

第二,当窗口旋转时,它给自己黑色子视图以明确隐藏任何否则会出现在窗口边界之外的视图.它将这些黑色子视图放置在其根视图控制器的视图前面.您需要将根视图控制器的视图移到前面,如下所示:

Second, when the window rotates, it gives itself black subviews to explicitly hide any views that would otherwise appear outside the window's bounds. It places these black subviews in front of its root view controller's view. You need to move your root view controller's view to the front, like this:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    UIWindow *window = self.view.window;
    [window bringSubviewToFront:window.rootViewController.view];
}

这篇关于我可以在没有黑条的情况下旋转 UIView 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆