Skip to content

Instantly share code, notes, and snippets.

@nataliepo
Created September 2, 2014 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nataliepo/a8c96205424d4e409035 to your computer and use it in GitHub Desktop.
Save nataliepo/a8c96205424d4e409035 to your computer and use it in GitHub Desktop.
observing a view's frame change
// 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