zoukankan      html  css  js  c++  java
  • IOS 使用横屏

    http://lizhuang.iteye.com/blog/1684881

    在iPad应用开发时如何让设备只支持横屏(landscape)模式,我做了多次尝试,并没有发现比较简捷的设置方法。我尝试了大概大概3种方式。 
    1、通过XCode设置“iPad Deployment info”,只选择横屏左和横屏右,部署测试后并没有生效,这种方法实质是在xxx_info.plist项目配置文件中添加如下信息: 
    <key>UISupportedInterfaceOrientations~ipad</key> 
    <array> 
    <string>UIInterfaceOrientationLandscapeLeft</string> 
    <string>UIInterfaceOrientationLandscapeRight</string> 
    </array> 
    2、通过对每个nib文件在IB中设置orientation为landscape,此法也不生效。 
    3、重载shouldAutorotateToInterfaceOrientation:方法,这种方式是可行的。具体如下: 
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

        // Return YES for supported orientations 
    return ((interfaceOrientation ==UIDeviceOrientationLandscapeLeft)||(interfaceOrientation ==UIDeviceOrientationLandscapeRight)); 

    如果第一种方式生效,那么比较完美。虽然第三种方式可以完全满足横屏的需求,但是实现起来比较stupid,需要在每个controller中都重载shouldAutorotateToInterfaceOrientation:方法,当然也可以通过扩展UIViewController的方式来避免重复劳动。但是感觉也有点不太直接,期待有人指出sdk本身是否就有简捷方式支持。 

    iPad的界面布局好多时候都要做两套------横屏和竖屏,但在界面切换时,该让哪个布局显示就要判断了,有多种方法,我记录下我用的一种,感觉比较方便: 
              NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; //Get the notification centre for the app 
        [nc addObserver:self //Add yourself as an observer 
               selector:@selector(orientationChanged) 
                   name:UIDeviceOrientationDidChangeNotification 
                 object:nil];//这个函数用来获取当前设备的方向, 
    - (void)orientationChanged 

        //UIView *ftView = [self.view viewWithTag:200]; 
        if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)//判断左右 
        { 
             //界面的新布局 
        } 
        if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait )//我有个方向不支持,如果想都支持那就不要这个if条件就行了 
        { 
             //界面的新布局 
        } 


    iOS 5 上真机测试过了。很方便,用过后才能体会到,这里不多说了!

  • 相关阅读:
    工作量单位-人月、人日、人时 详解
    PHP数组的交集array_intersect(),array_intersect_assoc(),array_inter_key()函数详解
    常用的Mysql数据库操作语句大全
    Linux服务器,PHP的10大安全配置实践
    PHP如何获取二个日期的相差天数?
    常见HTTP状态码列表
    PHP中静态(static)调用非静态方法详解
    PHP引用(&)初探:函数的引用返回
    PHP的大括号(花括号{})使用详解
    详解JavaScript中的Url编码/解码,表单提交中网址编码
  • 原文地址:https://www.cnblogs.com/apem/p/4021792.html
Copyright © 2011-2022 走看看