我可以观察一个UIViewController改变interfaceOrientation吗? [英] Can I observe when a UIViewController changes interfaceOrientation?

查看:63
本文介绍了我可以观察一个UIViewController改变interfaceOrientation吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个指向UIViewController的指针,当我改变interfaceOrientation而不修改控制器的代码时,我可以得到通知吗?

If I have a pointer to a UIViewController, can I be notified when it changes interfaceOrientation without modifying the code of the controller?

推荐答案

您可以使用NSNotificationCenter:

You can use 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");          
}

这篇关于我可以观察一个UIViewController改变interfaceOrientation吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆