欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS實(shí)現(xiàn)手動(dòng)和自動(dòng)屏幕旋轉(zhuǎn)

 更新時(shí)間:2022年07月20日 15:25:39   作者:z15083415803  
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)手動(dòng)和自動(dòng)屏幕旋轉(zhuǎn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了iOS實(shí)現(xiàn)手動(dòng)和自動(dòng)屏幕旋轉(zhuǎn)的具體代碼,供大家參考,具體內(nèi)容如下

首先iPhone中屏幕分為狀態(tài)欄方向和設(shè)備方向

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) {
? ? UIInterfaceOrientationUnknown ? ? ? ? ? ?= UIDeviceOrientationUnknown,
? ? UIInterfaceOrientationPortrait ? ? ? ? ? = UIDeviceOrientationPortrait,
? ? UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
? ? UIInterfaceOrientationLandscapeLeft ? ? ?= UIDeviceOrientationLandscapeRight,
? ? UIInterfaceOrientationLandscapeRight ? ? = UIDeviceOrientationLandscapeLeft
};

系統(tǒng)提供兩個(gè)地方來設(shè)置設(shè)備的方向,取兩個(gè)地方的交集是最后的設(shè)備所支持的方向

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window;
-(NSUInteger)supportedInterfaceOrientations;

這里需要注意的是返回的時(shí)下面的枚舉

typedef NS_OPTIONS(NSUInteger, UIInterfaceOrientationMask) {
? ? UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
? ? UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
? ? UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
? ? UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
? ? UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
? ? UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
? ? UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
};

在轉(zhuǎn)動(dòng)屏幕的時(shí)候會(huì)觸發(fā)下面方法

-(BOOL)shouldAutorotate;

在該方法返回真,自動(dòng)調(diào)用上面的兩個(gè)方法得到方向。

修改狀態(tài)欄方向的方法

1、使用私有API setOrientation;
2、修改狀態(tài)欄的方向,并通過設(shè)置View的transform來達(dá)到偽旋轉(zhuǎn)的結(jié)果,但是設(shè)備方向并沒有改變
3、主動(dòng)出發(fā)系統(tǒng)支持的方法,就相當(dāng)于讓這個(gè)vc在重新出來的時(shí)候系統(tǒng)判斷所支持的方向的機(jī)制重新走一遍。

- (void)awakeSupportInterOrtation:(UIViewController *)showVC completion:(void(^)(void))block
{
? ? UIViewController *vc = [[UIViewController alloc] init];
? ? void(^completion)() = ^() {
? ? ? ? [showVC dismissViewControllerAnimated:NO completion:^{
? ? ? ? ? ? if (block)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? block();
? ? ? ? ? ? }
? ? ? ? }];
? ? };

? ? // This check is needed if you need to support iOS version older than 7.0
? ? BOOL canUseTransitionCoordinator = [showVC respondsToSelector:@selector(transitionCoordinator)];

? ? if (canUseTransitionCoordinator)
? ? {
? ? ? ? [showVC presentViewController:vc animated:NO completion:nil];
? ? ? ? [showVC.transitionCoordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
? ? ? ? ? ? completion();
? ? ? ? }];
? ? }
? ? else
? ? {
? ? ? ? [showVC presentViewController:vc animated:NO completion:completion];
? ? }
}

-(NSUInteger)supportedInterfaceOrientations
{
? ? ? ? return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate
{
? ? return YES;
}

在需要轉(zhuǎn)為豎屏的時(shí)候調(diào)用一個(gè)方法,在后面兩個(gè)方法中如上實(shí)現(xiàn),第二個(gè)方法中返回的是你最終要轉(zhuǎn)向的方向。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS消息發(fā)送和轉(zhuǎn)發(fā)示例詳解

    iOS消息發(fā)送和轉(zhuǎn)發(fā)示例詳解

    這篇文章主要給大家介紹了關(guān)于iOS消息發(fā)送和轉(zhuǎn)發(fā)的相關(guān)資料,用Objective-C的術(shù)語來講,這叫做“給某個(gè)對(duì)象發(fā)送某條消息”。文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-03-03
  • H5混合開發(fā)IOS中遇到的坑

    H5混合開發(fā)IOS中遇到的坑

    本篇文章主要給大家講述了在用H5混合開發(fā)APP時(shí),IOS項(xiàng)目中遇到的坑以及解決辦法,需要的朋友參考一下吧。
    2017-12-12
  • iOS 圖片旋轉(zhuǎn)方法實(shí)例代碼

    iOS 圖片旋轉(zhuǎn)方法實(shí)例代碼

    這篇文章主要介紹了iOS 圖片旋轉(zhuǎn)方法實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-03-03
  • 詳解iOS自定義UITabBar與布局

    詳解iOS自定義UITabBar與布局

    本篇文章給大家詳細(xì)分析了iOS自定義UITabBar與布局的實(shí)際操作過程以及相關(guān)代碼分享,一起學(xué)習(xí)下。
    2018-02-02
  • iOS開發(fā)之UIPickerView實(shí)現(xiàn)城市選擇器的步驟詳解

    iOS開發(fā)之UIPickerView實(shí)現(xiàn)城市選擇器的步驟詳解

    這篇文章給大家介紹iOS利用控件UIPickerView實(shí)現(xiàn)城市選擇器的效果,選擇城市這一功能相信在大家日常開發(fā)的時(shí)候經(jīng)常遇見,下面就來看看詳細(xì)的實(shí)現(xiàn)過程,有需要的可以參考借鑒。
    2016-09-09
  • iOS 水波紋動(dòng)畫的實(shí)現(xiàn)效果

    iOS 水波紋動(dòng)畫的實(shí)現(xiàn)效果

    本篇文章主要介紹了iOS 水波紋的實(shí)現(xiàn)的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01
  • iOS開發(fā)中使用Picker View實(shí)現(xiàn)一個(gè)點(diǎn)菜應(yīng)用的UI示例

    iOS開發(fā)中使用Picker View實(shí)現(xiàn)一個(gè)點(diǎn)菜應(yīng)用的UI示例

    這篇文章主要介紹了iOS開發(fā)中使用Picker View實(shí)現(xiàn)一個(gè)點(diǎn)菜應(yīng)用的UI示例,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下
    2016-01-01
  • iOS實(shí)現(xiàn)屏幕亮度和閃光燈控制的實(shí)例代碼

    iOS實(shí)現(xiàn)屏幕亮度和閃光燈控制的實(shí)例代碼

    本篇文章主要介紹了iOS實(shí)現(xiàn)屏幕亮度和閃光燈控制的實(shí)例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下
    2017-06-06
  • iOS App使用GCD導(dǎo)致的卡頓現(xiàn)象及解決方法

    iOS App使用GCD導(dǎo)致的卡頓現(xiàn)象及解決方法

    這篇文章主要給大家介紹了關(guān)于iOS App使用GCD導(dǎo)致的卡頓現(xiàn)象及解決方法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • iOS獲取Label高度的幾種方法與對(duì)比

    iOS獲取Label高度的幾種方法與對(duì)比

    這篇文章主要介紹了給大家介紹了iOS獲取Label高度的幾種方法,包括 view的sizeThatFits 方法、view的sizeToFit方法、NSString的sizeWithAttributes方法和NSString 的 boundingRectWithSize 方法,文中不僅介紹四種方法的實(shí)現(xiàn),還進(jìn)行了對(duì)比,下面來一起看看吧。
    2016-11-11

最新評(píng)論