Created
October 6, 2012 20:01
-
-
Save leberwurstsaft/3845949 to your computer and use it in GitHub Desktop.
OLGhostAlertView Issue #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface LWSKeyboardListener : NSObject | |
@property (nonatomic, readonly) BOOL keyboardShowed; | |
@property (nonatomic, readonly) CGRect keyboardRect; | |
@property (nonatomic, readonly) CGFloat keyboardHeight; | |
+ (LWSKeyboardListener *)defaultListener; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "LWSKeyboardListener.h" | |
@implementation LWSKeyboardListener | |
+ (LWSKeyboardListener *)defaultListener { | |
static dispatch_once_t once; | |
static LWSKeyboardListener *sharedInstance; | |
dispatch_once(&once, ^{ | |
sharedInstance = [[self alloc] init]; | |
}); | |
return sharedInstance; | |
} | |
- (CGFloat)keyboardHeight { | |
return MIN(_keyboardRect.size.width, _keyboardRect.size.height); | |
} | |
#pragma mark - Life cycle | |
- (id)init { | |
self = [super init]; | |
if (self) { | |
[self registerNotifications]; | |
} | |
return self; | |
} | |
- (void)dealloc { | |
[self unregisterNotifications]; | |
} | |
#pragma mark - Register Notifications | |
- (void)registerNotifications { | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardDidShow:) | |
name:UIKeyboardDidShowNotification | |
object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardWillHide:) | |
name:UIKeyboardWillHideNotification | |
object:nil]; | |
} | |
- (void)unregisterNotifications { | |
[[NSNotificationCenter defaultCenter] removeObserver: self]; | |
} | |
#pragma mark - Handle notifications | |
- (void)keyboardDidShow:(NSNotification *)notif { | |
_keyboardShowed = YES; | |
NSValue *value = [[notif userInfo] objectForKey: UIKeyboardFrameEndUserInfoKey]; | |
_keyboardRect = [value CGRectValue]; | |
} | |
- (void)keyboardWillHide:(NSNotification *)notif { | |
_keyboardShowed = NO; | |
_keyboardRect = CGRectZero; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment