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

Fix iOS9 keyboard target. #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 25 additions & 11 deletions DAKeyboardControl/DAKeyboardControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

static inline UIViewAnimationOptions AnimationOptionsForCurve(UIViewAnimationCurve curve)
{
return curve << 16;
return curve << 16;
}

static char UIViewKeyboardTriggerOffset;
Expand Down Expand Up @@ -49,13 +49,13 @@ + (void)load
Method originalMethod = class_getInstanceMethod(self, originalSelector);
Method swizzledMethod = class_getInstanceMethod(self, swizzledSelector);
class_addMethod(self,
originalSelector,
class_getMethodImplementation(self, originalSelector),
method_getTypeEncoding(originalMethod));
class_addMethod(self,
swizzledSelector,
class_getMethodImplementation(self, swizzledSelector),
method_getTypeEncoding(swizzledMethod));
originalSelector,
class_getMethodImplementation(self, originalSelector),
method_getTypeEncoding(originalMethod));
class_addMethod(self,
swizzledSelector,
class_getMethodImplementation(self, swizzledSelector),
method_getTypeEncoding(swizzledMethod));
method_exchangeImplementations(originalMethod, swizzledMethod);
}

Expand Down Expand Up @@ -276,15 +276,15 @@ - (void)inputKeyboardWillShow:(NSNotification *)notification
- (void)inputKeyboardDidShow
{
// Grab the keyboard view
self.keyboardActiveView = self.keyboardActiveInput.inputAccessoryView.superview;
self.keyboardActiveView = [self findInputSetHostView];
self.keyboardActiveView.hidden = NO;

// If the active keyboard view could not be found (UITextViews...), try again
if (!self.keyboardActiveView)
{
// Find the first responder on subviews and look re-assign first responder to it
self.keyboardActiveInput = [self recursiveFindFirstResponder:self];
self.keyboardActiveView = self.keyboardActiveInput.inputAccessoryView.superview;
self.keyboardActiveView = [self findInputSetHostView];
self.keyboardActiveView.hidden = NO;
}
}
Expand Down Expand Up @@ -426,7 +426,7 @@ - (void)panGestureDidChange:(UIPanGestureRecognizer *)gesture
if(!self.keyboardActiveView || !self.keyboardActiveInput || self.keyboardActiveView.hidden)
{
self.keyboardActiveInput = [self recursiveFindFirstResponder:self];
self.keyboardActiveView = self.keyboardActiveInput.inputAccessoryView.superview;
self.keyboardActiveView = [self findInputSetHostView];
self.keyboardActiveView.hidden = NO;
}
else
Expand Down Expand Up @@ -550,6 +550,20 @@ - (UIView *)recursiveFindFirstResponder:(UIView *)view
return found;
}

-(UIView*) findInputSetHostView {
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0) {
for(UIWindow* window in [[UIApplication sharedApplication] windows])
if([window isKindOfClass:NSClassFromString(@"UIRemoteKeyboardWindow")])
for(UIView* subView in window.subviews)
if([subView isKindOfClass:NSClassFromString(@"UIInputSetHostView")])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--The class name here should be "UIInputSetContainerView"
Nvm this way seems works as well

for(UIView* subsubView in subView.subviews)
if([subsubView isKindOfClass:NSClassFromString(@"UIInputSetHostView")])
return subsubView;
} else
return self.keyboardActiveInput.inputAccessoryView.superview;
return nil;
}

- (void)swizzled_addSubview:(UIView *)subview
{
if (!subview.inputAccessoryView)
Expand Down