UIScrollView 不旋转到横向
这绝对是非常简单的事情,但它让我发疯,无法弄清楚。
非常简单,请参阅下面的解决方案
我的应用程序不会自动旋转。它只是卡在肖像中。
我的AppDelegate创建了一个viewController,其中shouldAutorotate未注释,并且简单地返回yes。
我的 viewController 设置一个滚动视图(x)作为它的视图,并添加一个子类化的自定义滚动视图(y)作为它的子视图。
比scrollview(y)添加UIView作为它的子视图。此 UIView 充当内容视图,并具有 1 个或多个其他 UIView 作为子视图。
所以:AppDelegate ->滚动视图(x)->滚动视图(y)-> UIView-> 1 个或多个 UIView
在调用 shouldAutorotate 时显示一行。当应用程序完成加载时,这种情况会发生 2 次。当我旋转模拟器时,没有任何反应,shouldAutorotate 显然没有被调用,因为我没有看到日志中显示一行。
UIScrollview 上是否有阻止其旋转的属性?
更新:我刚刚更改了 plist.info 以横向启动应用程序。现在,该应用程序停留在横向状态,并且不会旋转到纵向。
仅供参考:我没有使用界面生成器,所有操作都是在代码中完成的。
This is most def something very simple, but it is driving me crazy, cant figure it out.
It was very simple, see solution below
My app does not auto rotate. It is just stuck in portrait.
My AppDelegate creates a viewController witch has shouldAutorotate uncommented an simply returns yes.
My viewController sets up a scrollview(x) as it's view and adds a subclassed custom scrollview(y) as its subview.
Than scrollview(y) adds UIView as it's subview. This UIView acts as a content view and has 1 or multiple other UIViews as subview.
So: AppDelegate -> scrollView(x) -> scrollView(y) -> UIView -> 1 or more UIView's
I have a line displayed when shouldAutorotate is called. This happens 2x when the application has finished loading. When I rotate the simulator, nothing happens, shouldAutorotate is not called apparently because I don't see a line displayed in my log.
Is there a property on the UIScrollview which prevents it from rotating?
Update: I've just changed my plist.info to start the app in landscape. Now the app is stuck in landscape and does not rotate to portrait.
FYI: I'm not using interface builder, all done in code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案:事实证明我对记忆有点保守。在我的应用程序委托中,我将创建一个 viewController 的实例,将其添加到窗口中,然后对其调用release,认为它已添加到窗口中,因此我不再需要它了。坏主意。
因此,shouldAutorotate 消息被发送到不再存在的对象。我确实在控制台中收到一条关于消息被发送到已释放对象的消息,但在我旋转模拟器后仅几秒钟(20 左右)。
我了解到您应该始终保留对“main/root viewController”的引用作为 appDelegate 中的实例变量
Solution: Turns out I was a bit to memory conservative. In my app delegate I would create an instance of a viewController, add it to the window, and than called release on it, figuring it was added to the window so I wouldn't need it anymore. Bad idea.
The shouldAutorotate messages is therefore sent to an object that does not exist anymore. I did get a message in my console about a message being sent to a released object, but only multiple seconds (20 or so) after I rotated the simulator.
I've learned that you should always keep a reference to your "main/root viewController" as an instance variable in appDelegate