首页 编程 软件学院 查看内容

Xcode4.5.1、iPhone、iOS5、iOS6使用技巧

2013-2-25 15:47 918 0

摘要: 1.判断当前设备是iPad还是iPhoneiPodif([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPa...
关键词: UIInterfaceOrien 横竖 tation ToInterfaceOrien return 支持 interfaceOrienta shouldAutorotate 方向 Default

1.判断当前设备是iPad还是iPhone\iPodif([[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 image"[email protected]" 图片尺寸:Default.png 320x480 [email protected] 640x960 [email protected] 640x1136 5.根据iPhone5的宽和高,判断当前设备是不是iPhone5CGFloat 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
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部