zoukankan      html  css  js  c++  java
  • Sagit.Framework For IOS 开发框架入门教程16:屏幕旋转、屏幕强制旋转功能。

    前言:

    框架对屏蔽旋转做了很全面的封装处理,本篇来介绍一下使用屏幕旋转的相关功能。

    屏幕旋转的相关方法定义:

    #pragma mark 屏幕旋转
    //!屏幕旋转事件:【 return true 系统调用刷新布局([self.view refleshLayoutAfterRotate];);return false 用户自己手动控制】 @isEventRotate 是旋转屏幕、还是点击事件触发。
    typedef  BOOL(^OnRotate)(NSNotification* notify,BOOL isEventRotate);
    //!屏幕旋转事件。
    @property (nonatomic,assign) OnRotate onDeviceRotate;
    //!设置当前视图支持的屏幕旋转方向
    -(void)setSupportedInterfaceOrientations:(UIInterfaceOrientationMask)orientation;//!手动调用旋转屏幕。
    -(STController*)rotateOrientation:(UIInterfaceOrientation)direction;

    下面介绍具体的使用:

    1、【手动】设置屏幕【默认】的旋转

    -(void)onInit
    {
        [self rotateOrientation:UIInterfaceOrientationLandscapeRight];//设置旋转方向。
    
    }

    在初始化的地方,设置旋转,进入到该界面时,屏幕会自动旋转。

    2、【允许】系统自动的屏幕旋转

    -(void)onInit
    {
        [self rotateOrientation:UIInterfaceOrientationLandscapeRight];//设置默认方向。
    
        self.onDeviceRotate = ^BOOL(NSNotification *notify,BOOL isEventRotate) {
            //返回true允许旋转布局、false不允许旋转布局。
            return true;
        };
    }

    设置onDeviceRote属性后,可以除了可以控制系统屏蔽旋转,连手工旋转的也可以拦截。

    3、设置【允许】系统自动旋转的方向。

    -(void)onInit
    {
        [self rotateOrientation:UIInterfaceOrientationLandscapeRight];
        
    [self setSupportedInterfaceOrientations:UIInterfaceOrientationMaskLandscape];
    
        self.onDeviceRotate = ^BOOL(NSNotification *notify,BOOL isEventRotate) {
            return true;
        };
    }

    PS:

    1、手工旋转的,不受支持的方向的约束。

    2、设置支持的旋转方向,只能约束系统自动旋转手机产生的事件。 

  • 相关阅读:
    函数式编程
    scala 有 + 运算符吗?
    使用 Idea 打 scala程序的 jar 包
    相见恨晚的 scala
    半夜思考,为什么 String 具有不变性
    我的常用
    DataTable学习笔记
    Js 操作cookie
    嵌套的 ajax 请求
    Jquery插件收集【m了慢慢学】
  • 原文地址:https://www.cnblogs.com/cyq1162/p/13669370.html
Copyright © 2011-2022 走看看