zoukankan      html  css  js  c++  java
  • iPhone开发之在应用中从竖屏模式强制转换为横屏模式

    1.强制横屏模式,百度上找到很多方法,但是真正能用到项目上的却少之又少,有的是iOS版本太低的时候出的,过时了;有的方法被Apple官方私有化了。

    2.开发工具设置

    3.代码实现的两种方法

     (1) 此方法已经被Apple官方私有化,不能通过审核,但是用来实现简易测试非常方便

    1 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];

     (2)直接书写会出现报错,需要巧妙的转化绕过

    1    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
    2         [[UIDevice currentDevice] performSelector:@selector(setOrientation:)withObject:(id)UIInterfaceOrientationLandscapeRight];
    3     }

    ==>>转化后

    1   if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
    2         SEL selector = NSSelectorFromString(@"setOrientation:");
    3         NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
    4         [invocation setSelector:selector];
    5         [invocation setTarget:[UIDevice currentDevice]];
    6         int val = UIInterfaceOrientationLandscapeRight;
    7         [invocation setArgument:&val atIndex:2];
    8         [invocation invoke];
    9     }

    (3)当然这样强制之后屏幕的宽高也需要重新再确定(这点在Xcode5和Xcode6版本上可能会有所不同)

    pch

    //Xcode5
    #define HBScreenWidth  [[UIScreen mainScreen] bounds].size.height
    #define HBScreenHeight [[UIScreen mainScreen] bounds].size.width
    //Xcode6
    //#define HBScreenWidth  [[UIScreen mainScreen] bounds].size.width
    //#define HBScreenHeight [[UIScreen mainScreen] bounds].size.height

    .m

     1     CGFloat launchWidth  = HBScreenHeight;
     2     CGFloat launchHeight = HBScreenWidth;
     3     
     4     NSInteger imageCount = 4;
     5     _launchScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0, 0.0, launchWidth, launchHeight)];
     6     _launchScrollView.bounces = NO;
     7     _launchScrollView.pagingEnabled = YES;
     8     _launchScrollView.showsHorizontalScrollIndicator = NO;
     9     _launchScrollView.contentOffset = CGPointMake(0.0, 0.0);
    10     _launchScrollView.contentSize = CGSizeMake(launchWidth * imageCount, 0);

     (4) 关于NSInvocation有待进一步学习补充

    http://blog.csdn.net/nogodoss/article/details/23913499

    //iOS更新后的方法

    单个界面强制横屏,不能自动旋转,可由以下两句代替

    1 - (NSUInteger)supportedInterfaceOrientations
    2  {
    3      return UIInterfaceOrientationPortrait;
    4 } 
    5 
    6 - (BOOL)shouldAutorotate
    7 {
    8      return NO;
    9 }

     http://wenku.baidu.com/link?url=H3l4g_vkzbBrq7FeXOk0qqP7lIiUFC-SmBpCk5eBJDXxj81srFBV3Y93KmCDnTfAzNtsQC5HBgPO8fBx6b59mN84RNKhzgkyvq7-XTciUSm

  • 相关阅读:
    autocomplete="off" 不起作用
    IE8兼容模式设置
    H5学习
    wampserver安装配置
    HTML5音乐播放器(最新升级改造加强版)
    HTML5+CSS3+jquery实现简单的音乐播放器
    jquery+css3实现3d滚动旋转
    HTML5游戏设计与开发 小白7-9月的动态
    jquery submit()不执行
    html5手机常见问题与工具分享
  • 原文地址:https://www.cnblogs.com/HHB17/p/4176699.html
Copyright © 2011-2022 走看看