症状:
willRotateToInterfaceOrientation在ios5地下不执行,ios6 地下没事儿。
原因:
与 add subview 有关
具体原因,之前改了一段代码,详细参看,弹出键盘的怪事儿。导致页面结构变了。
结论:
看来ios 5 和 6 ,关于willRotateToInterfaceOrientation 是否执行,还是有点差别的。
解决办法,比较hack,
http://stackoverflow.com/questions/8016479/ios-5-willrotatetointerfaceorientationduration-not-called-when-first-loading-c
Since I'm pressed for time I've had to work around this odd behaviour and manually call the orientation methods in viewDidLoad. This is a bit of a hack but it's working fine so far.
In viewDidLoad I added this:
if ( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.0") ) {
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
[self willRotateToInterfaceOrientation:interfaceOrientation duration:0.2f];
}
I've then added this in a common header file:
// iOS Version Checking
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
I got the iOS version checking defines from an answer to this question on SO.
Since this is a bit of a hack I will leave this question unanswered for a little while just in case someone else finds a better way.
http://stackoverflow.com/questions/1516268/willrotatetointerfaceorientation-not-being-called
这个讲得也很好,虽然我已经知道了。
Is this views viewController a subview of some other root view controller thats not a navigation controller? if so then the call does not propagate to the subviews controller, so that might be why your view isnt rotating.