1.判断当前设备是iPad还是iPhone\iPod

 
  
  1. if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){  
  2.         NSLog(@"The Device is a iPad!");  
  3.     }else{  
  4.         NSLog(@"Not a iPad the device!");  
  5. }  

2.设置横屏或者竖屏或者横竖屏

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

  2. //横屏
  3.     //return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
  4. //竖屏
  5.     //return UIInterfaceOrientationIsPortrait(interfaceOrientation); 
  6. //横竖屏
  7.     //return YES;  

 

iOS5和iOS6横竖屏同时支持

iOS6中抛弃了如下这个方法 

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

为了同时支持iOS5和iOS6横竖屏切换,可用如下方法或代码

 
  
  1. 1 info.plist 中 Supported interface orientations中加入所有方向的支持 
  2. 2 AppDelegate中加入方法 
  3. -(NSUInteger)application:(UIApplication *)application 
  4. supportedInterfaceOrientationsForWindow:(UIWindow *)window
  5. return UIInterfaceOrientationMaskAll;
  6. } iOS6中为了后续支持任何方向的旋转 
  7. 3 任何你想控制旋转的界面中加入方法 
  8. // iOS6.0 
  9. -(NSUInteger)supportedInterfaceOrientations{ 
  10.     return UIInterfaceOrientationMaskPortrait;  // 可以修改为任何方向 
  11.   
  12. -(BOOL)shouldAutorotate{ 
  13.     return YES; 
  14.   
  15. // iOS5.0 
  16. -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 
  17.     return (toInterfaceOrientation == UIInterfaceOrientationPortrait);  // 可以修改为任何方向 
  18. 这样你的app就可以同时支持iOS5和iOS6系统的横竖屏切换了 

 

3.导入旧工程,解决Xcode4.5以后模拟器屏幕不旋转问题

 
  
  1. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0){ 
  2.         self.window.rootViewController = navigationCtrl
  3.     }else{ 
  4.         [self.window addSubview:navigationCtrl.view]; 
  5.     } 

4.支持iPhone5:添加Retina4 launch p_w_picpath"Default-568h@2x.png"

图片尺寸:

 
  
  1. Default.png  320x480 
  2. Default@2x.png  640x960        
  3. Default-568h@2x.png    640x1136 

5.根据iPhone5的宽和高,判断当前设备是不是iPhone5

 
  
  1. CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width; 
  2. CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height; 
  3. if ((screenWidth==568)||(screenHeight==568)) { 
  4.     isiPhone5 = YES

 注意:iPhone5的高是568,取得屏幕大小用

 
  
  1. [UIScreen mainScreen].bounds 

6.

 

7.

 

8.