Skip to content

Commit

Permalink
Refactor KVO
Browse files Browse the repository at this point in the history
  • Loading branch information
danielamitay committed Dec 26, 2012
1 parent 43abdaf commit 5647777
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions DAKeyboardControl/DAKeyboardControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ - (void)addKeyboardControl:(BOOL)panning actionHandler:(DAKeyboardDidMoveBlock)a
[self.keyboardPanRecognizer setDelegate:self];
[self addGestureRecognizer:self.keyboardPanRecognizer];
}

[self addObserver:self
forKeyPath:@"keyboardActiveView.frame"
options:0
context:NULL];
}

- (CGRect)keyboardFrameInView
Expand Down Expand Up @@ -195,6 +200,7 @@ - (void)removeKeyboardControl

// Unregister any gesture recognizer
[self removeGestureRecognizer:self.keyboardPanRecognizer];
[self removeObserver:self forKeyPath:@"keyboardActiveView.frame"];

// Release a few properties
self.keyboardDidMoveBlock = nil;
Expand Down Expand Up @@ -343,9 +349,9 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
change:(NSDictionary *)change
context:(void *)context
{
if([keyPath isEqualToString:@"frame"] && object == self.keyboardActiveView)
if([keyPath isEqualToString:@"keyboardActiveView.frame"] && self.keyboardActiveView)
{
CGRect keyboardEndFrameWindow = [[object valueForKeyPath:keyPath] CGRectValue];
CGRect keyboardEndFrameWindow = self.keyboardActiveView.frame;
CGRect keyboardEndFrameView = [self convertRect:keyboardEndFrameWindow fromView:self.keyboardActiveView.window];
if (self.keyboardDidMoveBlock && !self.keyboardActiveView.hidden)
{
Expand Down Expand Up @@ -611,15 +617,6 @@ - (UIView *)keyboardActiveView
- (void)setKeyboardActiveView:(UIView *)keyboardActiveView
{
[self willChangeValueForKey:@"keyboardActiveView"];
[self.keyboardActiveView removeObserver:self
forKeyPath:@"frame"];
if (keyboardActiveView)
{
[keyboardActiveView addObserver:self
forKeyPath:@"frame"
options:0
context:NULL];
}
objc_setAssociatedObject(self,
&UIViewKeyboardActiveView,
keyboardActiveView,
Expand Down

0 comments on commit 5647777

Please sign in to comment.