如果AViewContorller通过addSubview增加BViewController的view到界面中,当旋转iphone时,AViewController可以接到shouldAutorotateToInterfaceOrientation和- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration消息,但是在BViewController中是没有办法接到这个二
个消息的(目前我发现是这样的),但是如果是通过navigationController然后通过- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated这个方式
加入BViewController的话,是可以响应到二个方法的.
但是在我的工程中我需要通过AddSubview来增加BViewController的View,但是也希望旋转时也能接受到device旋转的消息.
目前我找到一种方法,共享给大家:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotificati*****];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:@"UIDeviceOrientationDidChangeNotification"
object:nil];
- (void) didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
{
}
}