Repo created
This commit is contained in:
parent
4af19165ec
commit
68073add76
12458 changed files with 12350765 additions and 2 deletions
18
iphone/Maps/Common/Keyboard/MWMKeyboard.h
Normal file
18
iphone/Maps/Common/Keyboard/MWMKeyboard.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#import "MWMKeyboardObserver.h"
|
||||
|
||||
@interface MWMKeyboard : NSObject
|
||||
|
||||
+ (void)applicationDidBecomeActive;
|
||||
|
||||
+ (void)addObserver:(id<MWMKeyboardObserver>)observer;
|
||||
+ (void)removeObserver:(id<MWMKeyboardObserver>)observer;
|
||||
|
||||
+ (CGFloat)keyboardHeight;
|
||||
|
||||
- (instancetype)init __attribute__((unavailable("call +manager instead")));
|
||||
- (instancetype)copy __attribute__((unavailable("call +manager instead")));
|
||||
- (instancetype)copyWithZone:(NSZone *)zone __attribute__((unavailable("call +manager instead")));
|
||||
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable("call +manager instead")));
|
||||
+ (instancetype)new __attribute__((unavailable("call +manager instead")));
|
||||
|
||||
@end
|
||||
98
iphone/Maps/Common/Keyboard/MWMKeyboard.m
Normal file
98
iphone/Maps/Common/Keyboard/MWMKeyboard.m
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#import "MWMKeyboard.h"
|
||||
|
||||
@interface MWMKeyboard ()
|
||||
|
||||
@property(nonatomic) NSHashTable *observers;
|
||||
@property(nonatomic) CGFloat keyboardHeight;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MWMKeyboard
|
||||
|
||||
+ (void)applicationDidBecomeActive {
|
||||
[self manager];
|
||||
}
|
||||
|
||||
+ (MWMKeyboard *)manager {
|
||||
static MWMKeyboard *manager;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
manager = [[self alloc] initManager];
|
||||
});
|
||||
return manager;
|
||||
}
|
||||
|
||||
- (instancetype)initManager {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_observers = [NSHashTable weakObjectsHashTable];
|
||||
NSNotificationCenter *nc = NSNotificationCenter.defaultCenter;
|
||||
[nc addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
|
||||
[nc addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[NSNotificationCenter.defaultCenter removeObserver:self];
|
||||
}
|
||||
|
||||
+ (CGFloat)keyboardHeight {
|
||||
return [self manager].keyboardHeight;
|
||||
}
|
||||
|
||||
#pragma mark - Add/Remove Observers
|
||||
|
||||
+ (void)addObserver:(id<MWMKeyboardObserver>)observer {
|
||||
[[self manager].observers addObject:observer];
|
||||
}
|
||||
|
||||
+ (void)removeObserver:(id<MWMKeyboardObserver>)observer {
|
||||
[[self manager].observers removeObject:observer];
|
||||
}
|
||||
|
||||
#pragma mark - Notifications
|
||||
|
||||
- (void)onKeyboardWillAnimate {
|
||||
for (id<MWMKeyboardObserver> observer in self.observers) {
|
||||
if ([observer respondsToSelector:@selector(onKeyboardWillAnimate)])
|
||||
[observer onKeyboardWillAnimate];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onKeyboardAnimation {
|
||||
for (id<MWMKeyboardObserver> observer in self.observers) {
|
||||
[observer onKeyboardAnimation];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)keyboardWillShow:(NSNotification *)notification {
|
||||
[self onKeyboardWillAnimate];
|
||||
CGSize keyboardSize = [notification.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
|
||||
self.keyboardHeight = MIN(keyboardSize.height, keyboardSize.width);
|
||||
NSNumber *duration = notification.userInfo[UIKeyboardAnimationDurationUserInfoKey];
|
||||
NSNumber *curve = notification.userInfo[UIKeyboardAnimationCurveUserInfoKey];
|
||||
[UIView animateWithDuration:duration.doubleValue
|
||||
delay:0
|
||||
options:curve.integerValue
|
||||
animations:^{
|
||||
[self onKeyboardAnimation];
|
||||
}
|
||||
completion:nil];
|
||||
}
|
||||
|
||||
- (void)keyboardWillHide:(NSNotification *)notification {
|
||||
[self onKeyboardWillAnimate];
|
||||
self.keyboardHeight = 0;
|
||||
NSNumber *duration = notification.userInfo[UIKeyboardAnimationDurationUserInfoKey];
|
||||
NSNumber *curve = notification.userInfo[UIKeyboardAnimationCurveUserInfoKey];
|
||||
[UIView animateWithDuration:duration.doubleValue
|
||||
delay:0
|
||||
options:curve.integerValue
|
||||
animations:^{
|
||||
[self onKeyboardAnimation];
|
||||
}
|
||||
completion:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
8
iphone/Maps/Common/Keyboard/MWMKeyboardObserver.h
Normal file
8
iphone/Maps/Common/Keyboard/MWMKeyboardObserver.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
@protocol MWMKeyboardObserver<NSObject>
|
||||
|
||||
- (void)onKeyboardAnimation;
|
||||
|
||||
@optional
|
||||
- (void)onKeyboardWillAnimate;
|
||||
|
||||
@end
|
||||
Loading…
Add table
Add a link
Reference in a new issue