我在使用uideviceorientationdidchangenotification时遇到一个小问题。在我离开某个viewController(viewwill消失:方法被调用)后,设备将不会停止发送通知。
这意味着,在我将另一个viewcontroller推到堆栈顶部并旋转设备后,将调用此处viewcontroller的receivedRotate:方法,而这是我不想要的。
我在文档和其他主题中也找不到任何内容。如果有人能帮忙,那就太好了。
我的场景如下:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
此时将显示视图:方法
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
最后,视图将消失:方法
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
事先谢谢!