ios5和ios6横竖屏支持及ipad和iphone设备的判断
来源:互联网 发布:失踪的宝贝知乎 编辑:程序博客网 时间:2024/04/28 07:17
判断是ipad还是iphone设备。此定义在PayViewControllerDemo-Prefix.pch
定义如下:
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define iPhone UIUserInterfaceIdiomPhone
#define iPad UIUserInterfaceIdiomPad
// ios5下的横屏需要调用的函数
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
ios5可以在每一个视图中取控制视图的方向,以及当视图切换不同方向时,去控制其子视图的布局,具体可以参照下列方式。
//界面视图里面有UIImageView和UIButton空间,当横竖屏时,坐标的改变。
@interfaceViewController ()
{PayViewController *payview;
UIImageView *drawViewipad;
UIImageView *drawViewihone;
UIButton *consumeBtnipone;
UIButton *consumeBtnipd;
}
//6.0之前
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (toInterfaceOrientation ==UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation ==UIInterfaceOrientationLandscapeRight)
{
if (isPad ==iPad)
{
drawViewipad.frame =CGRectMake(306, 150, 412, 120);
consumeBtnipd.frame =CGRectMake(1024/2-280/2,550, 280, 50);
}
else if (isPad ==iPhone)
{
drawViewihone.frame =CGRectMake(155, 50, 170, 60);
consumeBtnipone.frame =CGRectMake(170, 200, 140, 40);
}
}
if (toInterfaceOrientation ==UIInterfaceOrientationPortrait || toInterfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
{
if (isPad ==iPad)
{
drawViewipad.frame =CGRectMake(200, 150, 412, 120);
consumeBtnipd.frame =CGRectMake(768/2-280/2,550, 280, 50);
}
else if (isPad ==iPhone)
{
drawViewihone.frame =CGRectMake(85, 50,170, 60);
consumeBtnipone.frame =CGRectMake(90, 200,140, 40);
}
}
return YES;
}
// ios6下的横屏需要调用的函数
-(BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;//支持4各方向的旋转。
}
然后在plist文件里面找到Supported interface orientations 选项,添加你想支持的方向,都有提示的。
设置这个选项需要和代码一直,否则会出问题。
接着看如何控制每一个界面的方向及在不同方向界面的布局,由于ios6不能单独控制每一个界面的方向,所以需要由主viewcontroller来设置界面的控制,如果你有navgation,那么需要定义一个navgation的类,然后在此类中定义控制子viewcontroller的代码,如下:
//ios6之后需要在top-most controller中来控制方向问题。
-(BOOL)shouldAutorotate
{
return [self.viewControllers.lastObjectshouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.viewControllers.lastObjectsupportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.viewControllers.lastObjectpreferredInterfaceOrientationForPresentation];
}
如果没有navgation,那么就需要在appdelegate中去设置这段代码。
接着可以在任何子viewcontroller中来控制不同方向的view布局,可以参考子viewcontroller的代码布局,如下:
//ios6之后需要在top-most controller中来控制方向问题。
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
//判断系统的版本是6.0以上的。
if ([[UIDevicecurrentDevice]systemVersion].floatValue >= 6.0)
{
//判断设备当前的方向,然后重新布局不同方向的操作。
UIInterfaceOrientation currentOrientation = [[UIApplicationsharedApplication] statusBarOrientation];
if (currentOrientation ==UIInterfaceOrientationPortrait || currentOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
if (isPad ==iPad)
{
drawViewipad.frame =CGRectMake(200, 150, 412, 120);
consumeBtnipd.frame =CGRectMake(768/2-280/2,550, 280, 50);
}
else if (isPad ==iPhone)
{
drawViewihone.frame =CGRectMake(85, 50,170, 60);
consumeBtnipone.frame =CGRectMake(90, 200,140, 40);
}
}
if (currentOrientation ==UIInterfaceOrientationLandscapeLeft || currentOrientation ==UIInterfaceOrientationLandscapeRight)
{
if (isPad ==iPad)
{
drawViewipad.frame =CGRectMake(306, 150, 412, 120);
consumeBtnipd.frame =CGRectMake(1024/2-280/2,550, 280, 50);
}
else if (isPad ==iPhone)
{
drawViewihone.frame =CGRectMake(155, 50, 170, 60);
consumeBtnipone.frame =CGRectMake(170, 200, 140, 40);
}
}
}
returnUIInterfaceOrientationMaskAll;
}
这样就能控制不同方向的任何操作和界面布局了。
- ios5和ios6横竖屏支持及ipad和iphone设备的判断
- iOS5和iOS6横竖屏同时支持
- IOS iOS5和iOS6横竖屏同时支持
- IOS iOS5和iOS6横竖屏同时支持
- 关于ios6.0和5.0的横竖屏支持方法
- ipad和iphone横竖屏设置
- 如何同时支持IOS5和IOS6上的屏幕旋转?
- 如何同时支持IOS5和IOS6上的屏幕旋转?
- Iphone和Ipad判断
- iphone和ipad设备分辨率
- 判断ipad横竖屏的两个方法
- 问题解决:iOS6下shouldAutorotateToInterfaceOrientation不起作用,屏幕旋转同时支持iOS5和iOS6
- 问题解决:iOS6下shouldAutorotateToInterfaceOrientation不起作用,屏幕旋转同时支持iOS5和iOS6
- iphone,ipad横竖屏切换
- iphone/ipad 横竖屏切换
- iPad Android系统下,平板设备判断横竖屏,以及横竖屏变化之后的事件触发(html + javascript)
- iPad Android系统下,平板设备判断横竖屏,以及横竖屏变化之后的事件触发(html + javascript)
- 使程序同时支持iphone和ipad
- Expression Studio 4 Ultimate 中文版以及密钥(转)
- 判断素数问题(C语言实现)
- 论文格式设置-页面设置、页眉页脚、自动生成目录等
- PHP数组操作汇总
- php 操作数组 (合并,拆分,追加,查找,删除等)
- ios5和ios6横竖屏支持及ipad和iphone设备的判断
- Deformable Part Model的学习
- vs2012下 error4996
- hdu xxxx Peragrams
- fseek/ftell/rewind/fgetpos/fsetpos函数使用-linux
- Recover Binary Search Tree
- 《经济半小时》 20130906 指尖上的商机(五)数据时代
- 子程序重载
- Oracle中查询rownum和rowid的区别