对于手动添加到层次结构的视图旋转至横向 (iPhone)
我有一个简单的 UIViewController,它使用 XIB 作为其界面。
因此,界面简单地包括UIView、UIActivityIndicator和UILabel。我在 Interface Builder 中设置了大小限制,以在视图旋转时保持活动指示器和标签居中。
UIViewController 在 -shouldAutorotateToInterfaceOrientation:
方法中设置为针对纵向和横向返回 YES。
使用“我遇到的问题”手动将视图添加到视图层次结构中,
if (!activityOverlay)
activityOverlay = [[XBActivityOverlayViewController alloc] initWithNibName:@"XBActivityOverlayViewController" bundle:nil message:@"Connecting..."];
[activityOverlay.view setAlpha:0.0f];
[self.window addSubview:activityOverlay.view];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3f];
[activityOverlay.view setAlpha:0.9f];
[UIView commitAnimations];
如果设备已经处于横向方向并且此时将视图添加到层次结构中,则视图仍处于纵向方向,并且不会“自动旋转。
我需要做什么才能以与父视图相同的方向添加视图?
I have a simple UIViewController that uses a XIB for its interface.
As such, the interface simply comprises a UIView, a UIActivityIndicator and a UILabel. I have the sizing constraints in Interface Builder set to keep the activity indicator and the label centred when the view rotates.
The UIViewController is set to return YES for portrait and landscape orientations in the -shouldAutorotateToInterfaceOrientation:
method.
The view is added to the view hierarchy manually, using
if (!activityOverlay)
activityOverlay = [[XBActivityOverlayViewController alloc] initWithNibName:@"XBActivityOverlayViewController" bundle:nil message:@"Connecting..."];
[activityOverlay.view setAlpha:0.0f];
[self.window addSubview:activityOverlay.view];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3f];
[activityOverlay.view setAlpha:0.9f];
[UIView commitAnimations];
The problem I'm having is that if the device is already in landscape orientation and the view is added to the hierarchy at this point, the view is still in portrait orientation, and doesn't auto rotate.
What do I need to do to add the view in the same orientation as the parent view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道这是否是您问题的正确答案,但我希望能有所帮助:
对我来说,每次添加/关闭模式或显示新视图时,都会调用以下函数:
这里我根据当前设备方向。也许如果您检测到当前方向是横向,您可以添加具有此类方向的子视图。
亚历杭德拉:)
I do not know if it is the right answer to your question but I hope can help:
For me, every time I add/dismiss a modal or display a new view, the following function is called:
Here I change the position according to the current device orientation. Maybe if you detect that the current orientation is landscape you add a subview that has such orientation.
Alejandra :)