问题描述
有没有办法锁定 UIWebView 的方向?使用 Obj-C、JS 或 Html?我不想有按钮或任何东西,我只想在应用程序打开后立即将其锁定为纵向.
Is there a way to lock the orientation of a UIWebView? With Obj-C, JS, or Html? I don't want to have a button or anything I just want it to be locked to portrait as soon as the app opens up.
推荐答案
看起来这篇堆栈溢出帖子可以间接回答你的问题.当 iPhone 旋转时,会向顶级"视图发送通知,该视图负责布局其子视图.
Looks like this stack overflow post may indirectly answer your question. When the iPhone is rotated, the "top level" view is sent the notification, and that view is responsible for laying out its subviews.
如果你的 UIWebView 是顶层视图,它会自动旋转.但是,如果您将 UIWebView 放在另一个视图中,并让该容器"视图的视图控制器实现 shouldAutorateToInterfaceOrientation 方法,如下所示:
If your UIWebView is the top level view, it will autorotate itself. However, if you put the UIWebView inside of another view, and have the view controller for that "container" view implement the shouldAutorateToInterfaceOrientation method like this:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
这可能会阻止 UIWebView 知道界面已旋转.请注意,我还没有真正尝试过这个,但它应该可以工作.
That would probably prevent the UIWebView from knowing the interface was rotated. Note that I haven't actually tried this, but it should would work.
这篇关于iPhone 上的锁定方向 UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!