最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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è)地方來(lái)設(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)欄的方向,并通過(guò)設(shè)置View的transform來(lái)達(dá)到偽旋轉(zhuǎn)的結(jié)果,但是設(shè)備方向并沒(méi)有改變
3、主動(dòng)出發(fā)系統(tǒng)支持的方法,就相當(dāng)于讓這個(gè)vc在重新出來(lái)的時(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)文章

最新評(píng)論

彭山县| 乡宁县| 临澧县| 耒阳市| 常州市| 永清县| 廉江市| 玉田县| 鹤山市| 江阴市| 南岸区| 齐齐哈尔市| 贵南县| 崇左市| 静海县| 朝阳县| 绥江县| 昔阳县| 铅山县| 祥云县| 额济纳旗| 临泽县| 静乐县| 洞头县| 金沙县| 绍兴县| 蒙阴县| 临澧县| 孝感市| 深圳市| 安康市| 图木舒克市| 新密市| 鲁山县| 文成县| 新巴尔虎右旗| 湘潭县| 翁源县| 清丰县| 神农架林区| 夏津县|