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

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

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

本文實(shí)例為大家分享了iOS實(shí)現(xiàn)手動和自動屏幕旋轉(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)動屏幕的時(shí)候會觸發(fā)下面方法

-(BOOL)shouldAutorotate;

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

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

1、使用私有API setOrientation;
2、修改狀態(tài)欄的方向,并通過設(shè)置View的transform來達(dá)到偽旋轉(zhuǎn)的結(jié)果,但是設(shè)備方向并沒有改變
3、主動出發(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)向的方向。

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

相關(guān)文章

最新評論

陆河县| 嘉峪关市| 昌图县| 囊谦县| 西贡区| 扎赉特旗| 鄂托克旗| 克东县| 浦东新区| 杭锦后旗| 陵水| 库车县| 姚安县| 临夏县| 清新县| 习水县| 武隆县| 武陟县| 普格县| 荥阳市| 浑源县| 彝良县| 遵义县| 巴彦淖尔市| 阿图什市| 仁寿县| 大悟县| 清河县| 黄大仙区| 靖远县| 旬邑县| 广东省| 兴海县| 喀喇沁旗| 贡觉县| 磐石市| 沁阳市| 商洛市| 鄂托克前旗| 鄂尔多斯市| 高州市|