如果我有一个指向UIViewController的指针,是否可以在更改interfaceOrientation时通知我而不修改控制器的代码?
我最好选择检测设备方向的变化,然后看看UIViewController是否会旋转(d)?
小智 16
您可以使用NSNotificationCenter:
[[NSNotificationCenter defaultCenter] addObserver:self // put here the view controller which has to be notified
selector:@selector(orientationChanged:)
name:@"UIDeviceOrientationDidChangeNotification"
object:nil];
- (void)orientationChanged:(NSNotification *)notification{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
//do stuff
NSLog(@"Orientation changed");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9111 次 |
| 最近记录: |