获取屏幕旋转事件
来源:互联网 发布:免费横道图绘制软件 编辑:程序博客网 时间:2024/05/29 04:26
我下面介绍两种方法:
1.注册UIApplicationDidChangeStatusBarOrientationNotification通知(举例:在一个viewcontroller类的viewdidload中注册该通知),示例代码如下:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
- (void)statusBarOrientationChange:(NSNotification *)notification
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];if (orientation == UIInterfaceOrientationLandscapeRight) // home键靠右{ //}if ( orientation ==UIInterfaceOrientationLandscapeLeft) // home键靠左{ //}if (orientation == UIInterfaceOrientationPortrait){ //}if (orientation == UIInterfaceOrientationPortraitUpsideDown){ //}
}
注意这种方式监听的是StatusBar也就是状态栏的方向,所以这个是跟你的布局有关的,你的布局转了,才会接到这个通知,而不是设备旋转的通知。
当我们关注的东西和布局相关而不是纯粹设备旋转,我们使用上面的代码作为实现方案比较适合。
2.注册UIDeviceOrientationDidChangeNotification通知(举例:我们同样在一个viewcontroller类的viewdidload中注册该通知),示例代码如下:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
- (void)orientChange:(NSNotification *)noti
{
NSDictionary* ntfDict = [noti userInfo];UIDeviceOrientation orient = [UIDevice currentDevice].orientation;/* UIDeviceOrientationUnknown, UIDeviceOrientationPortrait, // Device oriented vertically, home button on the bottom UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top UIDeviceOrientationLandscapeLeft, // Device oriented horizontally, home button on the right UIDeviceOrientationLandscapeRight, // Device oriented horizontally, home button on the left UIDeviceOrientationFaceUp, // Device oriented flat, face up UIDeviceOrientationFaceDown // Device oriented flat, face down */ switch (orient) { case UIDeviceOrientationPortrait: break; case UIDeviceOrientationLandscapeLeft: break; case UIDeviceOrientationPortraitUpsideDown: break; case UIDeviceOrientationLandscapeRight: break; default: break; }
}
- 获取屏幕旋转事件
- Html5 屏幕旋转事件
- html5屏幕旋转事件
- html5屏幕旋转事件 onorientationchange
- Android 监听屏幕旋转事件
- html5屏幕旋转事件,html5如何实现屏幕旋转
- 爬爬爬之路:UI(三)自定义视图 MVC浅谈 视图控制器 屏幕旋转事件获取
- 屏幕旋转动画及api事件 iphone
- android整合--屏幕旋转触发事件
- WM6设置及获取屏幕旋转方向
- 获取 WinCE 移动设备屏幕旋转方向
- 旋转屏幕
- 屏幕旋转
- 屏幕旋转
- 屏幕旋转
- 旋转屏幕
- 屏幕旋转
- 屏幕旋转
- 来自知乎 python十分钟教程
- 详解匿名内部类
- 面向对象的陷阱——构造器的陷阱
- ANDROID LOG信息分析
- NYOJ123 士兵杀敌(四)(树状数组,插线问点)
- 获取屏幕旋转事件
- 数据存储之SQLite与LitePal<一>
- 4724: [POI2017]Podzielno
- 一个简单的爬虫开发
- Differences and Similarities Between Index Coalesce and Shrink Space
- linux中使用apt-get安装的文件位置
- mybatis动态执行自定义sql
- Android流畅性优化必备基础知识点---线程调度方式
- hdu 2018 母牛的故事