-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathUIViewController+KeyboardAnimation.h
More file actions
142 lines (126 loc) · 6.17 KB
/
UIViewController+KeyboardAnimation.h
File metadata and controls
142 lines (126 loc) · 6.17 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
//
// UIViewController+KeyboardAnimation.h
//
// Copyright (c) 2015 Anton Gaenko
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <UIKit/UIKit.h>
@interface UIViewController (KeyboardAnimation)
/**
* Block which contains user defined animations
*
* @param keyboardRect Finish keyboard frame
* @param duration Duration for keyboard showing animation
* @param isShowing If isShowing is YES we handle keyboard showing, if NO we process keyboard dismissing
*/
typedef void(^ANAnimationsWithKeyboardBlock)(CGRect keyboardRect, NSTimeInterval duration, BOOL isShowing);
/**
* Block to handle keyboard frame change
*
* @param keyboardRect Final keyboard frame
* @param duration Duration for keyboard frame changing animation
*/
typedef void(^ANFrameChangesAnimationsWithKeyboardBlock)(CGRect keyboardRect, NSTimeInterval duration);
/**
* Block to handle a start point of animation, could be used for simultaneous animations OR for setting some flags for internal usage.
*
* @param keyboardRect Finish keyboard frame
* @param duration Duration for keyboard showing animation
* @param isShowing If isShowing is YES we handle keyboard showing, if NO we process keyboard dismissing
*/
typedef void(^ANBeforeAnimationsWithKeyboardBlock)(CGRect keyboardRect, NSTimeInterval duration, BOOL isShowing);
/**
* Block to handle completion of keyboard animation
*
* @param finished If NO animation was canceled during performing
*/
typedef void(^ANCompletionKeyboardAnimations)(BOOL finished);
/**
* Animation block will be called inside [UIView animateWithDuration:::::]
*
* @tip viewWillAppear is the best place to subscribe to keyboard events
*
* @param animations User defined animations. If using auto layout don't forget to call layoutIfNeeded
* @param completion User defined completion block, will be called when animation ends
*
* @warning These blocks will he holding inside UIViewController which calls it, so as with any block-style API avoid a retain cycle
*/
- (void)an_subscribeKeyboardWithAnimations:(ANAnimationsWithKeyboardBlock)animations
completion:(ANCompletionKeyboardAnimations)completion;
/**
* Sinse version 1.3 it's a proxy for an_subscribeKeyboardWithAnimations:completion:
*/
- (void)an_subscribeKeyboardShowHideWithAnimations:(ANAnimationsWithKeyboardBlock)animations
completion:(ANCompletionKeyboardAnimations)completion;
/**
* Will call an_subscribeKeyboardShowHideWithAnimations with `nil` completion
*/
- (void)an_subscribeKeyboardShowHideWithAnimations:(ANAnimationsWithKeyboardBlock)animations;
/**
* Animation block will be called inside [UIView animateWithDuration:::::]
*
* @tip viewWillAppear is the best place to subscribe to keyboard events
*
* @param beforeAnimations Preanimation actions should be performed inside this block
* @param animations User defined animations. If using auto layout don't forget to call layoutIfNeeded
* @param completion User defined completion block, will be called when animation ends
*
* @warning These blocks will he holding inside UIViewController which calls it, so as with any block-style API avoid a retain cycle
*/
- (void)an_subscribeKeyboardWithBeforeAnimations:(ANBeforeAnimationsWithKeyboardBlock)beforeAnimations
animations:(ANAnimationsWithKeyboardBlock)animations
completion:(ANCompletionKeyboardAnimations)completion;
/**
* Sinse version 1.3 it's a proxy for an_subscribeKeyboardWithBeforeAnimations:animations:completion:
*/
- (void)an_subscribeKeyboardShowHideWithBeforeAnimations:(ANBeforeAnimationsWithKeyboardBlock)beforeAnimations
animations:(ANAnimationsWithKeyboardBlock)animations
completion:(ANCompletionKeyboardAnimations)completion;
/**
* Animation block will be called inside [UIView animateWithDuration:::::]
*
* @tip viewWillAppear is the best place to subscribe to keyboard events
*
* @param animations User defined animations. If using auto layout don't forget to call layoutIfNeeded
*
* @warning These blocks will be holding inside UIViewController which calls it, so as with any block-style API avoid a retain cycle
*/
- (void)an_subscribeKeyboardFrameChangesWithAnimations:(ANFrameChangesAnimationsWithKeyboardBlock)animations;
/**
*
* Call it to unsubscribe from keyboard events and clean all animations and completion blocks
*
* @tip viewWillDisappear is the best place to call it
*
* @warning If you will not call it when current view disappeared, subscribed view controller will handle keyboard events on other screens
*/
- (void)an_unsubscribeKeyboard;
/**
* Sinse version 1.3 it's a proxy for an_unsubscribeKeyboard
*/
- (void)an_unsubscribeKeyboardShowHide;
/**
*
* Call it to unsubscribe from keyboard frame change events and clean the animation block
*
* @tip viewWillDisappear is the best place to call it
*
* @warning If you will not call it when current view disappeared, subscribed view controller will handle keyboard events on other screens
*/
- (void)an_unsubscribeKeyboardFrameChanges;
@end