UIViewController不会自动旋转 [英] UIViewController does not auto rotate
问题描述
正如标题所说。无论怎样,我的UIViewController都不会旋转。当它加载时,调用了theAutorotateToInterfaceOrientation,但之后它没有被调用。
As the title says. My UIViewController will not rotate no matter what. When it loads shouldAutorotateToInterfaceOrientation is being called but after that it doesnt.
更新1:
UPDATE 1:
这是一个非常奇怪的问题。至少对于我来说。我将尝试解释一切。
It's a really really wierd problem. At least for me. And i ll try to explain everything.
这是一个基于导航的应用程序。每个控制器都有
It's a navigation based app. Every controller has
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;
}
Xcontroller是Acontroller的子节点,它不会自动旋转。如果Xcontroller成为Bcontroller的孩子,那么它将自动旋转。所以Acontroller出了问题。但Acontroller与Bcontroller相同(除了它的数据)。
Xcontroller is a child of Acontroller and it doesn't auto rotate. If Xcontroller become a child of Bcontroller then it will autorotate. So something is wrong with Acontroller. But Acontroller is identical (except its data) to Bcontroller.
什么是错的?
更新2:
UPDATE 2:
我决定重新创建Acontroller。它确实奏效了。我相信我错过了一些愚蠢的东西。
I decided to recreate Acontroller. And it worked.I believe I was missing something stupid.
推荐答案
我不确定这是否和你的情况一样。但我经历了同样的事情。 shouldAutorotateToInterfaceOrientation
仅在开始时调用一次。
通过分开代码进行一些严格的调试之后,我发现原因在于我的重写方法。
我之前有这个:
I am not sure whether it's the same reason as your case. But I experienced the same thing. the shouldAutorotateToInterfaceOrientation
was only called once in the beginning.
After some serious debugging by taking code apart, I found that the reason is in my overridden init method.
I had this before:
- (id)initWithAlbum:(PhotoAlbum *)theAlbum {
if (self) {
self.photoAlbum = theAlbum;
}
return self;
}
然后我改为此
- (id)initWithAlbum:(PhotoAlbum *)theAlbum {
if (self = [super init]) {
self.photoAlbum = theAlbum;
}
return self;
}
注意:唯一的区别是我加了 [super init]
调用父init。
完成此更改后,旋转效果很好,每次旋转屏幕时都会调用shouldAutorotateToInterfaceOrientation。
希望得到这个帮助。
Note: the only difference is I added [super init]
to call the parent init.
After this change, the rotation works well and the shouldAutorotateToInterfaceOrientation is being called everytime I rotate the screen.
Hope this help.
这篇关于UIViewController不会自动旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!