zoukankan      html  css  js  c++  java
  • UIInterfaceOrientation over iOS6 (应用旋转屏幕)

     
    typedef NS_ENUM(NSInteger, UIInterfaceOrientation) {
        UIInterfaceOrientationUnknown            = UIDeviceOrientationUnknown,
        UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
        UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
        UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
        UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
    };
    UIInterfaceOrientation enum 
    使App支持旋转
    有两种方法:
    1.选择Project->Target->General->Deployment Info->Device Orientation,勾选需要支持的屏幕方向,比如
         Portrait
         Upside Down
         Landscape Left
         Landscape Right
    2.在AppDelegate.m文件中,添加方法
    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscape;
    }
    以上面中的设置为例
    启动画面的方向取决于方法一,启动画面之后的Window方向取决于方法二,如果未实现方法二,则取决于方法一
     
    大部分页面为Portrait,个别页面为Landscape
    例如AppDelegate中的window的rootViewController为TabBarController,则TabBarController的ViewControllers的旋转方向都取决于TabBarController,因此需要在TabBarController中实现以下方法
    #import "TYSXTabBarController.h"
    
    #define kTabBarColor [UIColor colorWithRed:0.953f green:0.953f blue:0.953f alpha:1.00f]
    #define kTintColor [UIColor colorWithRed:0.914f green:0.000f blue:0.294f alpha:1.00f]
    
    @implementation TYSXTabBarController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.tabBar.translucent = NO;
        [self.tabBar setBarTintColor:kTabBarColor];
        self.tabBar.tintColor = kTintColor;
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    
    - (BOOL)shouldAutorotate
    {
        return YES;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationPortrait;
    }
    @end
    TabBarController.m

    这样,TabBarController下的所有页面就都只能是竖向了。

    如何让某个页面只能是横向的呢?

    以全屏播放页面(FullScreenViewController)为例,Present显示该页面,如此,播放页面就与TabBarController独立开了,在FullScreenViewController.m中实现以下方法

    @implementation FullScreenViewController
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscape;
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
    }
    
    @end
    FullScreenViewController.m
  • 相关阅读:
    bq25896 IINDPM 及 無 IINDPM 時的 regsiter
    不同狀況下的 bq25896 register
    bq25896 charging status CHRG_STAT register 0xB
    快充 IC BQ25896 如何判斷 手機插著 adapter 充電器時,adapter Iout 大於限制,adapter Vout 小於 限制,導致 battery 不但沒充電且還需放電。
    在 kernel 下打出 有帶參數的log。 怪異現象與解決方式。
    mtk flash tool,Win7 On VirtualBox
    java 去最后一位字符 str.substring(0,str.length()-1)
    Windows下Oracle的下载与安装及配置
    关于Java中SQL语句的拼接规则
    <id name="ID"> <generator class="assigned" /> </id>
  • 原文地址:https://www.cnblogs.com/ihojin/p/uiinterfaceorientation-over-ios6.html
Copyright © 2011-2022 走看看