Created
September 2, 2014 17:51
-
-
Save nataliepo/a8c96205424d4e409035 to your computer and use it in GitHub Desktop.
observing a view's frame change
This file contains 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
// create the observer | |
[[self contentView] addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:NULL]; | |
// track changes | |
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { | |
if ([object isKindOfClass:[UIView class]]) { | |
CGRect rect = [[change valueForKey:NSKeyValueChangeNewKey] CGRectValue]; | |
NSLog(@"changed rect: %@", NSStringFromCGRect(rect)); | |
// Cell * cell = (Cell*)[self.tableView cellForRowAtIndexPath:self.activeIndexDelete]; | |
} | |
} | |
// removing observer | |
@try{ | |
[[self contentView] removeObserver:self forKeyPath:@"frame"]; | |
} | |
@catch (id exception) { | |
// do something | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment