Iphone UIDeviceOrientationIDChangeNotification赢得';停不下来

Iphone UIDeviceOrientationIDChangeNotification赢得';停不下来,iphone,objective-c,orientation,Iphone,Objective C,Orientation,我在使用UIDeviceOrientationIDChangeNotification时遇到了一个小问题。在我离开某个ViewController(调用ViewWillEnglish:方法)后,设备不会停止发送通知 这意味着,在我将另一个ViewController推到堆栈顶部并旋转设备后,将调用ViewController的receivedRotate:方法,我不希望调用该方法 我在这里的文档和其他主题中找不到任何内容。如果有人能帮忙,那就太好了 我的设想如下: - (void)viewDid

我在使用UIDeviceOrientationIDChangeNotification时遇到了一个小问题。在我离开某个ViewController(调用ViewWillEnglish:方法)后,设备不会停止发送通知

这意味着,在我将另一个ViewController推到堆栈顶部并旋转设备后,将调用ViewController的receivedRotate:方法,我不希望调用该方法

我在这里的文档和其他主题中找不到任何内容。如果有人能帮忙,那就太好了

我的设想如下:

- (void)viewDidLoad {
    [super viewDidLoad];

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];

     // other things...
}
此时将显示视图:方法

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
最后,视图将消失:方法

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}

提前谢谢

-视图将消失:
,删除观察者:

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];

谢谢你的回答。它与以下解决方案一起工作:我添加了代码以删除ViewWillEnglish中的观察者:但必须在ViewWillEnglish中添加观察者:因为视图第二次出现时,观察者不会被添加。但是,我仍然不理解BegingeratingDeviceOrientationNotifications和endGeneratingDeviceOrientationNotifications的含义。在我的应用程序中,两者都不会影响通知的触发。通知总是被触发?!?!应用程序运行时会发出各种通知,包括方向更改通知。但是,除非类(z.B.视图控制器)已注册以侦听这些通知,否则该类将不会“侦听”通知,也不会对其采取行动。如何自定义类的行为,如何指定它们如何响应各种系统级通知,取决于您自己。@AlexReynolds:我认为您不理解schaechtele的评论。BegingeratingDeviceNotifications的文档说,除非调用此方法,否则不会生成有关设备方向更改的事件,但我也观察到它在不调用此方法的情况下生成通知。我想这是一个系统范围内的事情,如果任何其他应用程序已经打开了方向通知,那么你也将在不调用BegingeratingDeviceOrientationNotifications的情况下获得它们。