美文网首页
ios实现屏幕旋转的方法

ios实现屏幕旋转的方法

作者: 梁景华Joshua_ | 来源:发表于2016-05-08 00:15 被阅读480次

1、屏蔽AppDelegate下面的屏幕旋转方法

#pragma mark - 屏幕旋转的
//-(UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window {
// return UIInterfaceOrientationMaskPortrait;
//}````

2、对UINavigationController和UITabBarController写两个扩展类别,此东西不需要在具体的ViewController中引用
UINavigationController+Autorotate.h

````//
//  UINavigationController+Autorotate.h
//  fitmiss
//
//  Created by bill on 15/12/16.
//  Copyright © 2015年 lear. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UINavigationController (Autorotate)

@end````


UINavigationController+Autorotate.m

````//
//  UINavigationController+Autorotate.m
//  fitmiss
//
//  Created by bill on 15/12/16.
//  Copyright © 2015年 lear. All rights reserved.
//

#import "UINavigationController+Autorotate.h"


@implementation UINavigationController (Autorotate)

- (BOOL)shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.topViewController preferredInterfaceOrientationForPresentation];
}

@end````

UITabBarController+Autorotate.h

````//
//  UITabBarController+Autorotate.h
//  fitmiss
//
//  Created by bill on 15/12/16.
//  Copyright © 2015年 lear. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UITabBarController (Autorotate)

@end````

UITabBarController+Autorotate.m

````//
//  UITabBarController+Autorotate.m
//  fitmiss
//
//  Created by bill on 15/12/16.
//  Copyright © 2015年 lear. All rights reserved.
//

#import "UITabBarController+Autorotate.h"

@implementation UITabBarController (Autorotate)

- (BOOL)shouldAutorotate
{
    return [self.selectedViewController shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations
{
    return [self.selectedViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}

@end````

3.在使用的ViewController中的再次重写这三个方法,可以在根ViewController中重写如下方法,就能实现竖屏,子ViewController再重写实现旋转

  • (BOOL)shouldAutorotate {
    //是否允许转屏
    return NO;
    }
  • (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    //viewController所支持的全部旋转方向
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
  • (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ //viewController初始显示的方向
    return UIInterfaceOrientationPortrait;
    }

注意:在使用的时候发现在ios9以下的版本出现一个奇怪的问题,就是编译出来的app默认是横的,解决办法是看app.plist下面Supported interface orientations里的列表中,正屏的是不是排在第一个。

[转自:http://www.cnblogs.com/lear/p/5051818.html](http://www.cnblogs.com/lear/p/5051818.html)

相关文章

  • iOS传感器:实现一个随屏幕旋转的图片

    iOS传感器:实现一个随屏幕旋转的图片 iOS传感器:实现一个随屏幕旋转的图片

  • ios实现屏幕旋转的方法

    1、屏蔽AppDelegate下面的屏幕旋转方法 (BOOL)shouldAutorotate {//是否允许转屏...

  • 屏幕旋转和弹出框

    iOS中控制屏幕旋转相关方法 shouldAutorotate:是否支持屏幕旋转 alertView:clicke...

  • iOS Rotation

    iOS屏幕旋转学习笔记iOS开发中使用屏幕旋转功能的相关方法 1、基本知识点解读 了解屏幕旋转首先需要区分两种 o...

  • iOS 屏幕旋转,单个屏幕旋转的实现

    闲来无事研究了一下屏幕旋转的问题 说到屏幕旋转问题不得先说一句,做项目尽量还是优先使用storyboard、IB因...

  • 屏幕旋转

    屏幕旋转 推荐文档 了解UIWindow——UIWindow实践 iOS屏幕旋转问题总结 IOS:屏幕旋转与变换 ...

  • iOS屏幕旋转方法

    1 . 比较好的旋转屏幕的方法如下: 这样做的话在模拟器中会发现模拟器也随着变成了横屏 2 .通过setTrans...

  • iOS屏幕旋转控制,极简

    iOS屏幕旋转控制的简单实现,使用方式也非常简单,需要控制旋转的UIViewController遵守ShouldN...

  • iOS-屏幕旋转截屏相关

    本篇收录各种屏幕旋转知识点等. 1.详解iOS开发中处理屏幕旋转的几种方法2.iOS 个别页面强制横屏,其他页面竖...

  • Runtime解决屏幕旋转问题

    前言 大家或许在iOS程序开发中经常遇到屏幕旋转问题,比如说希望指定的页面进行不同的屏幕旋转,但由于系统提供的方法...

网友评论

      本文标题:ios实现屏幕旋转的方法

      本文链接:https://www.haomeiwen.com/subject/nudsrttx.html