iPhone开发应用中如何以消息通知方式设置旋转View

移动开发 iOS
iPhone开发应用中以消息通知方式设置旋转View是本文要介绍的内容,主要是来学如何来旋转View,具体内容来看本文详解。

iPhone开发应用中以消息通知方式设置旋转View是本文要介绍的内容,主要是来学如何来旋转View,具体内容来看本文详解。看到这篇不错, 直接转载过来了, 没什么可解释的,一看就明白 :)。

整个程序需要支持横竖屏切换得时候,会比较简单,在每个ViewController 的

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

方法中,return YES; 就好。

可如果只是要某个VC( = View Controller)支持横竖屏切换呢?单独在那个view controller中像上面那样做是没有效果的。

这个时候我们可以取 UIDevice的 Orientation来判定:

1、在VC中注册 UIDevice 的 UIDeviceOrientationDidChangeNotification 通知:

  1. NSNotificationCenter *center = [NSNotificationCenter defaultCenter];  
  2. [center addObserver:self selector:@selector(doRotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

2、在自己的 doRotate函数里面处理:

  1. - (void)doRotate:(NSNotification *)notification{  
  2. UIDevice *myDevice = [UIDevice currentDevice];  
  3. UIDeviceOrientation deviceOrientation = [myDevice orientation];  
  4. UIApplication *app = [UIApplication sharedApplication];  
  5. [app setStatusBarOrientation:deviceOrientation];  

3.

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

也是要 return YES。

小结:iPhone开发应用中以消息通知方式设置旋转View的内容介绍完了,希望通过本文的学习能对你有所帮助!

责任编辑:zhaolei 来源: marsiphone
相关推荐

2011-08-17 15:10:21

iPhone开发Web视图

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2022-09-16 11:19:25

失败开发

2011-08-18 16:42:07

iPhone应用APNS推送

2017-08-31 16:39:57

2011-08-15 15:44:46

iPhone开发PDF

2011-08-18 16:24:44

iPhone开发图片

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-08-12 14:33:06

iPhone缓存文件

2011-08-22 14:12:48

iPhone开发NSTableView

2011-08-15 11:37:20

iPhone开发Mask

2011-08-19 14:34:03

iPhone开发

2011-08-11 14:09:27

iPhoneModalViewCoView

2012-04-26 13:26:58

iPhone应用技巧

2018-08-23 08:13:01

Linux命令

2011-08-12 13:35:23

iPhone文件流ASIHTTPRequ

2011-08-12 09:48:24

iPhoneCoreLocatio定位

2011-08-16 15:48:37

iPhone开发抓图程序

2011-08-15 13:44:07

iPhone开发UITableView

2011-08-08 13:50:29

iPhone开发 NSOperatio 多线程
点赞
收藏

51CTO技术栈公众号