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 上真机测试过了。很方便,用过后才能体会到,这里不多说了!

时间: 2024-07-29 00:12:58

IOS 使用横屏的相关文章

iOS设备横屏时,frame和bounds的分别

工程中有两个ViewControllers,其中ViewController是root view controller,底色是红色,上面有一个按钮,点击后加载GreenViewController,并显示其视图,底色是绿色. 首先是ViewController的代码: #import "ViewController.h" #import "GreenViewController.h" @interface ViewController () @end @implem

iOS强制横屏

iOS强制横屏的两种方式: 第1种:设置状态栏方向,然后vc.view设置transform旋转.注意:VC需要设置为不支持横屏. [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES]; [UIView animateWithDuration:0.25 animations:^{ self.view.transform = CGAf

iOS支持横屏旋转, 常规方法和强制选择

横屏支持 常规方法支持旋转 // controller的内容是否支持自动旋转 - (BOOL)shouldAutorotate { return YES; } 模拟器iOS7.1 : 转横屏时,被调用:横屏转竖屏,也被调用. 模拟器iOS8.0 : 转横屏时,被调用:横屏转竖屏,不被调用. 模拟器iOS9.0 : 转横屏时,被调用:横屏转竖屏,也被调用. http://stackoverflow.com/questions/26503423/shouldautorotate-behavior-i

iOS的横屏(Landscape)与竖屏(Portrait)InterfaceOrientation

转自:http://www.molotang.com/articles/1530.html 接着上篇写的触摸事件,这次借机会整理下iOS横屏和竖屏的翻转方向支持,即InterfaceOrientation相关的内容. 最近做一个页面,最初并没有太多考虑orientation的情况,当其嵌入到一个在iPad上使用横屏(Landscape)的应用中,就会只显示在屏幕的左面,而且貌似还没显示全,这个……很丑!发自内心地觉得这么做对不起苹果的设计理念!对不起乔老爷子... 改!说到该就要了解苹果开发中对

iOS关掉横屏后某单个页面横竖屏切换

在你想支持横竖屏的viewController里面重写两个方法: // 支持设备自动旋转 - (BOOL)shouldAutorotate {     return YES; } // 支持横竖屏显示 - (NSUInteger)supportedInterfaceOrientations {     return UIInterfaceOrientationMaskAll; } 这样在这个viewController中就可以横竖屏切换了. 但是,如果你window的rootViewContro

iOS 强制横屏

// // AAAAViewController.m // hengp // // Created by 朱信磊 on 15/2/13. // Copyright (c) 2015年 niit. All rights reserved. // #import "AAAAViewController.h" #import "AppDelegate.h" @interface AAAAViewController () @end @implementation AAAA

iOS 视频播放横屏,隐藏状态栏

MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] init]; moviePlayerViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width); moviePlayerViewController.view.ce

ios和android适配

一些情况下对非可点击元素如(label,span)监听click事件,ios下不会触发 解决方案:css增加cursor:pointer; 三星手机遮罩层下的input.select.a等元素可以被点击和focus(点击穿透) 问题发现于三星手机,这个在特定需求下才会有,因此如果没有类似问题的可以不看.首先需求是浮层操作,在三星上被遮罩的元素依然可以获取focus.click.change),有两种解决方案: 1.是通过层显示以后加入对应的class名控制,截断显示层下方可获取焦点元素的事件获取

ios8无法横屏的猜测

昨天晚上,更新了ios8.1,结果产品始终无法横屏(一直是竖屏),无论你怎么设置.其实,是ios8把当作横屏了.关于这个问题,网友也有讨论http://www.unitymanual.com/thread-26716-1-1.html 大家的意思是xcode6 与 ios8 有些地方不兼容(而我恰恰也是xcode6),于是我就顺着人家的提示改,改了半天也没改出来.由于代码每一次build时间都不短,真把我耐心磨没了. 后来一想,是不是我unity的问题,马上看 unity是4.3.2.顿时喷涌出