ios5和ios6横竖屏支持及ipad和iphone设备的判断

判断是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);

}

}

returnYES;

}

// 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

{

returnYES;

}

- (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设备的判断的更多相关文章

  1. iOS5 and iOS6都只支持横屏的方法

    If your app uses a UINavigationController, then you should subclass it and set the class in IB. You ...

  2. Android 横竖屏+碎片的应用

    最终效果展示: 项目介绍: 通过碎片的方式显示标题列表和内容,其中也牵涉到横竖屏的知识 项目代码下载:http://files.cnblogs.com/files/Laopengblog/%E7%A2 ...

  3. Activity 横竖屏切换

    前言 在开发中常要处理横竖屏切换,怎么处理先看生命周期 申明 Activity 横竖屏切换时需要回调两个函数 ,所以在此将这个两个函数暂时看成是Activity 横竖屏切换的生命周期的一部分,这两个函 ...

  4. Android应用:横竖屏切换总结

    眨眼间,已经到了2016你年春节前,离上一篇博客的时间已经有6个月多,回想起这半年的种种,不得不说,学习和工作实在是太忙了,或许这就是程序员的真实写照吧. 写博客之初,主要的目的还是为了把自己的学习痕 ...

  5. js判断手机的横竖屏调整样式

    在移动端,我们经常遇到横竖屏的问题,所以我们改如何判断或针对横竖屏来写代码呢.首先需要在head中加入如下代码: <meta name="viewport" content= ...

  6. iOS开发UI篇—iPad和iPhone开发的比较

    一.iPad简介 1.什么是iPad 一款苹果公司于2010年发布的平板电脑 定位介于苹果的智能手机iPhone和笔记本电脑产品之间 跟iPhone一样,搭载的是iOS操作系统 2.iPad的市场情况 ...

  7. 【转】iOS开发UI篇—iPad和iPhone开发的比较

    原文网址:http://www.cnblogs.com/wendingding/p/3918007.html iOS开发UI篇—iPad和iPhone开发的比较 一.iPad简介 1.什么是iPad ...

  8. iPad和iPhone开发的比较

    一.iPad简介 1.什么是iPad 一款苹果公司于2010年发布的平板电脑 定位介于苹果的智能手机iPhone和笔记本电脑产品之间 跟iPhone一样,搭载的是iOS操作系统 2.iPad的市场情况 ...

  9. iPad和iPhone开发的异同

    niPad和iPhone开发的异同   niPad简介 n什么是iPad p一款苹果公司于2010年发布的平板电脑 p定位介于苹果的智能手机iPhone和笔记本电脑产品之间 p跟iPhone一样,搭载 ...

随机推荐

  1. [置顶] 九度笔记之 1434:今年暑假不AC

    题目1434:今年暑假不AC 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:307 解决:180 题目描述: “今年暑假不AC?”“是的.”“那你干什么呢?”“看世界杯呀,笨蛋!”“@# ...

  2. |,&,<<,>>运算符

    << 位移运算符(>>相反了) /* * 题目: 2 << 3 = 10000 = 16 * 解答: 2向左移动三位,就变成了10000 * 十进制 二进制 * 2 ...

  3. Hibernate绑定参数

    使用绑定参数的优势: 我们为什么要使用绑定命名参数?任何一个事物的存在都是有其价值的,具体到绑定参数对于HQL查询来说,主要有以下两个主要优势:①. 可以利用数据库实施性能优化 因为对Hibernat ...

  4. Spring源代码由浅入深系列五 GetBean

    获取bean的过程如上图所看到的.下一章将继续图示解说createBean的过程. blog宗旨:用图说话 附:文件夹 Spring源代码由浅入深系列四 创建BeanFactory Spring源代码 ...

  5. 网络编程API-下 (I/O复用函数)

    IO复用是Linux中的IO模型之中的一个,IO复用就是进程预先告诉内核须要监视的IO条件,使得内核一旦发现进程指定的一个或多个IO条件就绪,就通过进程进程处理.从而不会在单个IO上堵塞了. Linu ...

  6. toj2867 Picking Problem

    题目链接:http://acm.tju.edu.cn/toj/showp.php?pid=2867 题目大意:给定一系列活动的开始时间和结束时间,问最多能参加的活动数目 思路:// 本题属于最大区间调 ...

  7. 提高你的Java代码质量吧:小心switch带来的空值异常

    一.分析  使用枚举定义常量时,会有伴有大量的switch语句判断,目的是为每个枚举解释其行为. 我们知道,目前的Java的switch语句只能判断byte.short.char.int类型(JDK7 ...

  8. Java - 反射机制 2

    package spring.classloader; import java.lang.reflect.Constructor; import java.lang.reflect.Field; im ...

  9. 【Java基础】setter与getter方法

    //下面代码实现设置和获取学生姓名和成绩. class lesson5homework { public static void main(String[] args) { TestCode TC=n ...

  10. c# 面相对象4-多态性

    一.定义: 多态是面向对象程序设计的又一个特性.在面向过程的程序设计中,主要工作是编写一个个的过程或函数,这些过程和函数不能重名.例如在一个应用中,需要对数值型数据进行排序,还需要对字符型数据进行排序 ...