ios 屏幕旋转大全
来源:互联网 发布:抚仙湖尸库 知乎 编辑:程序博客网 时间:2024/06/08 11:05
如果希望所有界面不可以旋转 则可也在Target —> general 的 device orientation 禁止掉就可以了
或者也可以在AppDelegate中增加,这个方法可以禁止横屏
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}
一般我们都是希望某个页面可以选装例如 图片浏览的页面可以横屏,我这里例子图片浏览界面的图片浏览框架出自(code4app mj哥的一个demo)
加速计是整个IOS屏幕旋转的基础,依赖加速计,设备才可以判断出当前的设备方向,IOS系统共定义了以下七种设备方向:
typedef NS_ENUM(NSInteger, UIDeviceOrientation) { UIDeviceOrientationUnknown, UIDeviceOrientationPortrait, // Device oriented vertically, home button on the bottom UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top UIDeviceOrientationLandscapeLeft, // Device oriented horizontally, home button on the right UIDeviceOrientationLandscapeRight, // Device oriented horizontally, home button on the left UIDeviceOrientationFaceUp, // Device oriented flat, face up UIDeviceOrientationFaceDown // Device oriented flat, face down};以及如下四种界面方向:
typedef NS_ENUM(NSInteger, UIInterfaceOrientation) { UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft}; 我这里整体是一个tabbarController的程序1、定义tabbarController的子类
- //
- // BaseTabBarViewController.m
- // WithBusiness
- //
- // Created by king on 14-6-18.
- // Copyright (c) 2014年 sinosoft. All rights reserved.
- //
- #import "BaseTabBarViewController.h"
- #import "MJPhotoBrowser.h"
- #import "BaseNavigationViewController.h"
- @interface BaseTabBarViewController ()
- @end
- @implementation BaseTabBarViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- //6.0之前
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- if ([[self getTopViewController] isKindOfClass:[MJPhotoBrowser class]]) {
- return [(MJPhotoBrowser*)[self getTopViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
- }
- //禁止旋转
- return (interfaceOrientation==UIInterfaceOrientationPortrait);
- }
- //6.0之后 包括6.0
- - (BOOL)shouldAutorotate
- {
- if ([[self getTopViewController] isKindOfClass:[MJPhotoBrowser class]]) {
- return YES;
- //这里我直接return yes 也可也return 下面这行代码 由topViewController来做控制
- // return [[self getTopViewController] shouldAutorotate];
- }
- return NO;
- }
- //
- - (NSUInteger)supportedInterfaceOrientations
- {
- if ([[self getTopViewController] isKindOfClass:[MJPhotoBrowser class]]) {
- return [(MJPhotoBrowser*)[self getTopViewController] supportedInterfaceOrientations];
- }
- //返回UIDeviceOrientationPortraitUpsideDown, 当在图片浏览界面横屏返回上一页面的时候会自动恢复到竖屏
- return UIDeviceOrientationPortraitUpsideDown;
- }
- -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
- {
- return [[self getTopViewController] willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
- }
- //获取最顶层的ViewController
- - (id)getTopViewController{
- BaseNavigationViewController *navCtr = (BaseNavigationViewController*)self.selectedViewController;
- BaseUIViewController *viewController = (BaseUIViewController *)navCtr.topViewController;
- return viewController;
- }
- @end
在mjBrowser的类里面
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight
- ||[[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait
- ||[[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeLeft){
- return YES;
- }
- return NO;
- }
- - (BOOL)shouldAutorotate
- {
- if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight
- ||[[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait
- ||[[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeLeft){
- return YES;
- }
- return NO;
- }
- -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
可以里面做一些横屏操作
判断是否横屏:
- if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight
- ||[[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeLeft) {
- _screen_change = YES;
- }
0 0
- ios 屏幕旋转大全
- iOS手动旋转屏幕、自动旋转屏幕
- ios屏幕旋转注意事项
- iOS强制旋转屏幕
- ios 锁定 屏幕旋转
- ios旋转屏幕总结
- [IOS] 屏幕旋转控制
- iOS屏幕旋转
- 手动旋转iOS屏幕
- iOS屏幕旋转
- ios屏幕旋转
- iOS屏幕旋转
- IOS屏幕旋转
- iOS 屏幕旋转
- ios屏幕强制旋转
- ios 屏幕旋转
- ios屏幕旋转
- ios--屏幕旋转
- 虚析构函数作用
- 嵌套事务回滚示例
- 彩票中奖机软件机器码会改变吗?
- 非的风格的风格
- java快速开发平台
- ios 屏幕旋转大全
- lua5.1 和 5.2 关于 sequence 的定义变化,对#table取值的影响
- Mysq中模式匹配
- 13_android项目中记录ListView滚动停止位置与设置显示位置
- Java下json的解析方法-----GSON与JSONObject
- linux shell脚本中的$,$*,$@和$#
- Android中Animation动画的介绍及用法
- valgrind-linux下检测内存工具
- vc状态栏的使用