我不确定“常规控制器”是什么意思,但是如果您想在每个 UIViewControllers 的方向更改时收到通知,那么您可以创建实现didRotateFromInterfaceOrientation:
方法的抽象 UIViewController,您可以在其中发布自定义通知。比让每个 UIViewController 成为那个抽象 UIViewController 的子类。例如。
#import <UIKit/UIKit.h>
@interface MyAbstractViewController : UIViewController
@end
@implementation MyAbstractViewController
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyNotificationName" object:self];
}
@end
创建你的 UIViewControllers 作为 MyAbstractViewController 的子类
#import <UIKit/UIKit.h>
#import "MyAbstractViewController.h"
@interface ViewController : MyAbstractViewController
@end
将所需对象作为“MyNotificationName”的观察者
#import <Foundation/Foundation.h>
@interface MyController : NSObject
@end
@implementation MyController
-(id)init {
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(vcDidChangeOrientation:) name:@"MyNotificationName" object:nil];
return self;
}
return nil;
}
-(void)vcDidChangeOrientation:(NSNotification *)notification {
UIViewController *vController = (UIViewController *)[notification object];
//Do whatever you want to do with it
}
@end