BDPopupController.h
6.73 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//
// BDPopupController.h
// <https://github.com/snail-z/BDPopupController.git>
//
// Created by zhanghao on 2016/11/15.
// Copyright © 2017年 snail-z. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// Control view mask style
typedef NS_ENUM(NSUInteger, zhPopupMaskType) {
zhPopupMaskTypeDarkBlur = 0,
zhPopupMaskTypeLightBlur,
zhPopupMaskTypeExtraLightBlur,
zhPopupMaskTypeWhite,
zhPopupMaskTypeClear,
zhPopupMaskTypeBlackOpacity // default
};
/// Control the style of view Presenting
typedef NS_ENUM(NSInteger, zhPopupSlideStyle) {
zhPopupSlideStyleFromTop = 0,
zhPopupSlideStyleFromBottom,
zhPopupSlideStyleFromLeft,
zhPopupSlideStyleFromRight,
zhPopupSlideStyleFade, // default
zhPopupSlideStyleTransform
};
/// Control where the view finally position
typedef NS_ENUM(NSUInteger, zhPopupLayoutType) {
zhPopupLayoutTypeTop = 0,
zhPopupLayoutTypeBottom,
zhPopupLayoutTypeLeft,
zhPopupLayoutTypeRight,
zhPopupLayoutTypeCenter // default
};
/// Control the display level of the PopupController
typedef NS_ENUM(NSUInteger, zhPopupWindowLevel) {
zhPopupWindowLevelVeryHigh = 0,
zhPopupWindowLevelHigh,
zhPopupWindowLevelNormal, // default
zhPopupWindowLevelLow,
zhPopupWindowLevelVeryLow
};
@protocol BDPopupControllerDelegate;
@interface BDPopupController : NSObject
@property (nonatomic, weak) id <BDPopupControllerDelegate> _Nullable delegate;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
/// Designated initializer,Must set your content view and its size.
/// Bind the view to a popup controller,one-to-one
- (instancetype)initWithView:(UIView *)popupView size:(CGSize)size;
/// The view is the initialized `popupView`
@property (nonatomic, strong, readonly) UIView *view;
/// Whether contentView is presenting.
@property (nonatomic, assign, readonly) BOOL isPresenting;
/// Set popup view mask style. default is zhPopupMaskTypeBlackOpacity (maskAlpha: 0.5)
@property (nonatomic, assign) zhPopupMaskType maskType;
/// Set popup view display position. default is zhPopupLayoutTypeCenter
@property (nonatomic, assign) zhPopupLayoutType layoutType;
/// Set popup view present slide style. default is zhPopupSlideStyleFade
@property (nonatomic, assign) zhPopupSlideStyle presentationStyle;
/// Set popup view dismiss slide style. default is `presentationStyle`
@property (nonatomic, assign) zhPopupSlideStyle dismissonStyle;
/// Set popup view priority. default is zhPopupWindowLevelNormal
@property (nonatomic, assign) zhPopupWindowLevel windowLevel;
/// default is 0.5, When maskType is zhPopupMaskTypeBlackOpacity vaild.
@property (nonatomic, assign) CGFloat maskAlpha;
/// default is 0.5, When slideStyle is zhPopupSlideStyleTransform vaild.
@property (nonatomic, assign) CGFloat presentationTransformScale;
/// default is `presentationTransformScale`, When slideStyle is zhPopupSlideStyleTransform vaild.
@property (nonatomic, assign) CGFloat dismissonTransformScale;
/// default is YES. if NO, Mask view will not respond to events.
@property (nonatomic, assign) BOOL dismissOnMaskTouched;
/// The view will disappear after `dismissAfterDelay` seconds,default is 0 will not disappear
@property (nonatomic, assign) NSTimeInterval dismissAfterDelay;
/// default is NO. if YES, Popup view will allow to drag
@property (nonatomic, assign) BOOL panGestureEnabled;
/// When drag position meets the screen ratio the view will dismiss,default is 0.5
@property (nonatomic, assign) CGFloat panDismissRatio;
/// Adjust the layout position by `offsetSpacing`
@property (nonatomic, assign) CGFloat offsetSpacing;
/// Adjust the spacing between with the keyboard
@property (nonatomic, assign) CGFloat keyboardOffsetSpacing;
/// default is NO. if YES, Will adjust view position when keyboard changes
@property (nonatomic, assign) BOOL keyboardChangeFollowed;
/// default is NO. if the view becomes first responder,you need set YES to keep the animation consistent
/// If you want to make the animation consistent:
/// You need to call the method "becomeFirstResponder()" in "willPresentBlock", don't call it before that.
/// You need to call the method "resignFirstResponder()" in "willDismissBlock".
@property (nonatomic, assign) BOOL becomeFirstResponded;
/// Block gets called when internal trigger dismiss.
@property (nonatomic, copy) void (^defaultDismissBlock)(BDPopupController *popupController);
/// Block gets called when contentView will present.
@property (nonatomic, copy) void (^willPresentBlock)(BDPopupController *popupController);
/// Block gets called when contentView did present.
@property (nonatomic, copy) void (^didPresentBlock)(BDPopupController *popupController);
/// Block gets called when contentView will dismiss.
@property (nonatomic, copy) void (^willDismissBlock)(BDPopupController *popupController);
/// Block gets called when contentView did dismiss.
@property (nonatomic, copy) void (^didDismissBlock)(BDPopupController *popupController);
@end
@interface BDPopupController (Convenient)
/// shows popup view animated in window
- (void)show;
/// shows popup view animated.
- (void)showInView:(UIView *)view completion:(void (^ __nullable)(void))completion;
/// shows popup view animated using the specified duration.
- (void)showInView:(UIView *)view duration:(NSTimeInterval)duration completion:(void (^ __nullable)(void))completion;
/// shows popup view animated using the specified duration and bounced.
- (void)showInView:(UIView *)view duration:(NSTimeInterval)duration bounced:(BOOL)bounced completion:(void (^ __nullable)(void))completion;
/// shows popup view animated using the specified duration, delay, options, bounced, and completion handler.
- (void)showInView:(UIView *)view duration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options bounced:(BOOL)bounced completion:(void (^ __nullable)(void))completion;
/// hide popup view animated
- (void)dismiss;
/// hide popup view animated using the specified duration.
- (void)dismissWithDuration:(NSTimeInterval)duration completion:(void (^ __nullable)(void))completion;
/// hide popup view animated using the specified duration, delay, options, and completion handler.
- (void)dismissWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options completion:(void (^ __nullable)(void))completion;
@end
@protocol BDPopupControllerDelegate <NSObject>
@optional
// - The Delegate method, block is preferred.
- (void)popupControllerWillPresent:(BDPopupController *)popupController;
- (void)popupControllerDidPresent:(BDPopupController *)popupController;
- (void)popupControllerWillDismiss:(BDPopupController *)popupController;
- (void)popupControllerDidDismiss:(BDPopupController *)popupController;
@end
NS_ASSUME_NONNULL_END