BBAOrientationManager.h
4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// BBAOrientationManager.h
// rotation
//
// Created by liuchengqing01 on 2017/9/24.
// Copyright © 2017年 baidu. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UIWindow+BBAInterfaceOrientations.h"
NS_ASSUME_NONNULL_BEGIN
// 强制转屏判断结果
typedef enum : NSUInteger {
BBAForceOrientationCheckResultYes, // 转屏
BBAForceOrientationCheckResultNo, // 不转屏
BBAForceOrientationCheckResultUndefined, // 不确定
} BBAForceOrientationCheckResult;
@interface BBAOrientationManager : NSObject
+ (instancetype _Nullable)shareInstance;
#pragma mark - auto rotate controller
/*
横竖屏状态更新规则:
1. vc不支持当前设备的横竖屏状态, 更新到偏好横竖屏状态
2. vc支持当前设备的横竖屏状态, 但当前横竖屏状态与设备的横竖屏状态不一致, 更新到设备的横竖屏状态
3. vc支持当前设备的横竖屏状态, 且当前横竖屏状态与设备的横竖屏状态一致, 无需进行更新
4. vc不支持当前横竖屏状态, 立即更新状态
5. vc支持当前横竖屏状态, 待调用updateOrientationIfNeeded时更新状态
*/
/**
给即将展示的vc设置转向更新请求 (默认有动画)
*/
- (void)setNeedUpdateOrientationAdaptToViewController:(UIViewController *_Nullable)viewcontroler;
- (void)setNeedUpdateOrientationAdaptToViewController:(UIViewController *_Nullable)viewControler animation:(BOOL)animation;
- (void)setNeedUpdateOrientationAdaptToViewController:(UIViewController *_Nullable)viewControler window:(UIWindow *)window animation:(BOOL)animation;
/**
清除转向更新请求
*/
- (void)clearUpdateOrientation;
/**
跳过下一次转向更新(即updateOrientationIfNeeded),如PopFromLandscapeToPortraitOrientation与pushRootViewcontroller
*/
- (void)skipNextUpdateOrientation;
/**
转向更新, 无转向请求直接跳过
*/
- (void)updateOrientationIfNeeded;
/**
强制旋屏(默认app主window)
*/
- (void)forceRotateToOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated completion:(void (^ __nullable)(BOOL finished))completion;
/**
强制旋屏(指定window)
*/
- (void)forceRotateWindow:(UIWindow *_Nonnull)window toOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated completion:(void (^ __nullable)(BOOL finished))completion;
/**
检查并强制旋屏(指定window)
备注:如果当前window与目标方向一致,立即执行回调
*/
- (void)checkAndForceRotateWindow:(UIWindow *_Nonnull)window toOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated completion:(void (^ __nullable)(BOOL finished))completion;
#pragma mark - window rotate controller
/*
自定义window旋转屏控制:
1.createOrientationManagerViewController作为window的RootViewcontroller
2.自定义window的RootViewcontroller, 使用Manager中提供shouldAutorotate与supportedInterfaceOrientations作为RootViewcontroller的旋转控制
3.自定义window的RootViewcontroller, 自己控制旋转
*/
/**
需要自动转屏
*/
@property (nonatomic, assign, readonly) BOOL needAutorotate;
/**
正在更新的横竖屏状态
*/
@property (nonatomic, assign, readonly) UIInterfaceOrientation adaptingOrientation;
/**
横竖屏状态控制主容器
*/
@property (nonatomic, weak, readonly) UIViewController *rootViewController;
/**
手势转场时转屏控制
*/
@property (nonatomic, assign) BOOL cannotRotate;
/**
设置控制旋转的主vc容器, 需KeyWindow的rootViewController
*/
- (void)setupRootViewController:(UIViewController *_Nullable)rootViewController;
/**
是否可以旋转, 由rootViewController控制
*/
- (BOOL)shouldAutorotate;
/**
旋转方向支持, 由rootViewController控制
*/
- (UIInterfaceOrientationMask)supportedInterfaceOrientations;
/// 起始方向, 由rootViewController控制
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
/**
控制旋转的vc, 用于作为自定义window的RootViewcontroller
*/
- (UIViewController *_Nullable)createOrientationManagerViewController;
/**
保持住对应横竖屏状态(慎用, 使用后会使系统转屏停留在固定的状态, forceRotateToOrientation无效, 该函数不会触发转屏动作, hold的状态需与当前的状态一致)
*/
- (void)holdOrientation:(UIInterfaceOrientation)orientation;
/**
解除保持横竖屏状态(需与holdOrientation成对使用)
*/
- (void)cancelHoldOrientation;
/**
强制转屏检查
*/
- (BBAForceOrientationCheckResult)checkForceAutorotate;
@end
NS_ASSUME_NONNULL_END