Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix for frame observing on iOS 8 #82

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions DAKeyboardControl/DAKeyboardControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#import "DAKeyboardControl.h"
#import <objc/runtime.h>

#ifndef SYSTEM_VERSION_LESS_THAN
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#endif

static inline UIViewAnimationOptions AnimationOptionsForCurve(UIViewAnimationCurve curve)
{
Expand All @@ -25,6 +28,8 @@ static inline UIViewAnimationOptions AnimationOptionsForCurve(UIViewAnimationCur
static char UIViewIsPanning;
static char UIViewKeyboardOpened;

static NSString *UIViewKeyboardObservingKey;

@interface UIView (DAKeyboardControl_Internal) <UIGestureRecognizerDelegate>

@property (nonatomic) DAKeyboardDidMoveBlock frameBasedKeyboardDidMoveBlock;
Expand Down Expand Up @@ -57,6 +62,8 @@ + (void)load
class_getMethodImplementation(self, swizzledSelector),
method_getTypeEncoding(swizzledMethod));
method_exchangeImplementations(originalMethod, swizzledMethod);

UIViewKeyboardObservingKey = SYSTEM_VERSION_LESS_THAN(@"8") ? @"frame" : @"center";
}

#pragma mark - Public Methods
Expand Down Expand Up @@ -372,9 +379,9 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
change:(__unused NSDictionary *)change
context:(__unused void *)context
{
if([keyPath isEqualToString:@"frame"] && object == self.keyboardActiveView)
if([keyPath isEqualToString:UIViewKeyboardObservingKey] && object == self.keyboardActiveView)
{
CGRect keyboardEndFrameWindow = [[object valueForKeyPath:keyPath] CGRectValue];
CGRect keyboardEndFrameWindow = self.keyboardActiveView.frame;
CGRect keyboardEndFrameView = [self convertRect:keyboardEndFrameWindow fromView:self.keyboardActiveView.window];

if (CGRectEqualToRect(keyboardEndFrameView, self.previousKeyboardRect)) return;
Expand Down Expand Up @@ -688,11 +695,11 @@ - (void)setKeyboardActiveView:(UIView *)keyboardActiveView
{
[self willChangeValueForKey:@"keyboardActiveView"];
[self.keyboardActiveView removeObserver:self
forKeyPath:@"frame"];
forKeyPath:UIViewKeyboardObservingKey];
if (keyboardActiveView)
{
[keyboardActiveView addObserver:self
forKeyPath:@"frame"
forKeyPath:UIViewKeyboardObservingKey
options:0
context:NULL];
}
Expand Down