1.判断当前设备是iPad还是iPhone\iPod
- if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
- NSLog(@"The Device is a iPad!");
- }else{
- NSLog(@"Not a iPad the device!");
- }
2.设置横屏或者竖屏或者横竖屏
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- //横屏
- //return UIInterfaceOrientationIsLandscape(interfaceOrientation);
- //竖屏
- //return UIInterfaceOrientationIsPortrait(interfaceOrientation);
- //横竖屏
- //return YES;
- }
iOS5和iOS6横竖屏同时支持
iOS6中抛弃了如下这个方法
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
为了同时支持iOS5和iOS6横竖屏切换,可用如下方法或代码
- 1 info.plist 中 Supported interface orientations中加入所有方向的支持
- 2 AppDelegate中加入方法
- -(NSUInteger)application:(UIApplication *)application
- supportedInterfaceOrientationsForWindow:(UIWindow *)window{
- return UIInterfaceOrientationMaskAll;
- } iOS6中为了后续支持任何方向的旋转
- 3 任何你想控制旋转的界面中加入方法
- // iOS6.0
- -(NSUInteger)supportedInterfaceOrientations{
- return UIInterfaceOrientationMaskPortrait; // 可以修改为任何方向
- }
- -(BOOL)shouldAutorotate{
- return YES;
- }
- // iOS5.0
- -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
- return (toInterfaceOrientation == UIInterfaceOrientationPortrait); // 可以修改为任何方向
- }
- 这样你的app就可以同时支持iOS5和iOS6系统的横竖屏切换了
3.导入旧工程,解决Xcode4.5以后模拟器屏幕不旋转问题
- if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0){
- self.window.rootViewController = navigationCtrl;
- }else{
- [self.window addSubview:navigationCtrl.view];
- }
4.支持iPhone5:添加Retina4 launch p_w_picpath"Default-568h@2x.png"
图片尺寸:
- Default.png 320x480
- Default@2x.png 640x960
- Default-568h@2x.png 640x1136
5.根据iPhone5的宽和高,判断当前设备是不是iPhone5
- CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;
- CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
- if ((screenWidth==568)||(screenHeight==568)) {
- isiPhone5 = YES;
- }
注意:iPhone5的高是568,取得屏幕大小用
- [UIScreen mainScreen].bounds
6.
7.
8.