关于设置iphone程序的横屏和竖屏模式的问题

来源:互联网 发布:利为汇seo营销培训 编辑:程序博客网 时间:2024/05/29 13:48

设置iphone程序的横屏和竖屏模式:

iPhone的横屏竖屏针对iOS系统版本分为两种开发方式: 一种是iOS 6之前的使用模式 一种是iOS6的新模式. 两者的区别还是蛮大的.

iOS6之前通常使用 shouldAutorotateToInterfaceOrientation 来单独控制某个UIViewController的方向,需要哪个viewController支持旋转,只需要重写shouldAutorotateToInterfaceOrientation方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
{  
   return UIInterfaceOrientationIsLandscape(interfaceOrientation);  // return YES 
}  


iOS6之后使用如下两个方法控制自动旋转,分别是:
 [csharp]   
- (BOOL)shouldAutorotate  
{  
    NSLog(@"让不让我旋转?");  
    return YES;  
}  
  
- (NSUInteger)supportedInterfaceOrientations {  
    NSLog(@"让我旋转哪些方向");  
    return UIInterfaceOrientationMaskAllButUpsideDown;  
}  


那么在自动旋转触发后,系统会自动调用另外两个方法:
 
[csharp]  
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {  
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];  
    NSLog(@"将要旋转了?");  
}  
  
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {  
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];  
    NSLog(@"如果让我旋转,我已经旋转完了!");  
      
}  

使用xib进行界面设计时,改变xib的横竖显示方式



以上方法都是通过代码来实现的 下面介绍一种简单的方法  (xcode 5 && ios6 以上)


1 找到  工程中 ***info.plist 文件


2 点击进入 找到最后一项: 

 

protrait 为竖屏(肖像)模式

landscape 为横屏(风景)模式


设置应用程序为永远竖屏:

方法1: 讲 item1 和item2 两项删除 

方法2: 讲两项对应string改为 protrait 






0 0