将指定视图设置为横向模式时出现问题

发布于 2024-10-25 01:28:26 字数 487 浏览 2 评论 0原文

我确实寻找可能的答案,但没有找到。我的问题是,我只希望应用程序中的一个视图(显示图像)同时处于纵向和横向模式,而其他视图仅处于纵向模式。

该视图作为其子视图添加到 [[[UIApplication sharedApplication] delegate] window] 中。

我在 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

[self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];- (void)viewDidLoad

,但是当我转动设备时,视图不会旋转。请告诉我哪里做错了或者还需要做什么。

I did look for possible answers but found none. my problem is that I only want one of the views in my app (which shows an image) to be in both portrait and landscape mode, while other views in portrait only.

this view is added to [[[UIApplication sharedApplication] delegate] window] as its subview.

and i set return YES in - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

and also [self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; in - (void)viewDidLoad

but when i turn the device the view doesn't rotate. please tell me where i did wrong or what more needs to be done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我太投入 2024-11-01 01:28:26

据我所知,子视图(例如您添加的子视图)仅在所属容器视图传递该消息时才会发送一条消息,表示设备已旋转。如果您使用 UINavigationController 或 UITabBar 并将视图添加到其中,那么它就已经为您完成了,但是如果您将视图直接添加到窗口中,那么它就不是了。

编辑:您可以使用 UIDeviceOrientationDidChangeNotification 与 NSNotificationCenter。

As far as I know, a subview (such as the one you added) is only sent the message saying the device has rotated if the owning container view passes it along. If you use a UINavigationController or UITabBar and add your view to that it is done for you, but if you add the view directly to the window as you have it isn't.

EDIT: you can capture the device orientation changing yourself using UIDeviceOrientationDidChangeNotification with NSNotificationCenter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文