Ios KVO-接口方向属性

Ios KVO-接口方向属性,ios,uiinterfaceorientation,key-value-observing,Ios,Uiinterfaceorientation,Key Value Observing,我试图通过以下代码通过UIViewController的KVO从其他对象观察界面方向: [((UIViewController *)self.delegate) addObserver:self forKeyPath:@"interfaceOrientation" options:NSKeyValueObservingOptionNew context:NULL]; 以及执行该职能: -(void)observeValueForKeyPath:(NSString*)keyPath ofObje

我试图通过以下代码通过UIViewController的KVO从其他对象观察界面方向:

[((UIViewController *)self.delegate) addObserver:self forKeyPath:@"interfaceOrientation" options:NSKeyValueObservingOptionNew context:NULL];
以及执行该职能:

-(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context 
{
 if ([keyPath isEqual:@"interfaceOrientation"]) 
  {
    // do something    
  }
}
该方法仅在第一次调用,尽管我可以看到代理的属性interfaceOrientation在我旋转手机时发生了变化

为什么?

请帮忙


谢谢

你为什么要用KVO做这件事?UIViewController内置了对此的支持。看

  //iOS6 only
 - (BOOL)shouldAutomaticallyForwardRotationMethods
 {
    return YES;
 }

还有
addChildViewController:

如果它不是视图控制器视图的子视图?该视图是窗口的子视图。