I am creating a UIView
that can alter the gestureRecognizers
that are added to itself. Just to test it out I am adding a tap gesture right after adding the observer to trigger the KVO.
- (void)awakeFromNib
{
[self addObserver:self forKeyPath:@"gestureRecognizers" options:NSKeyValueObservingOptionNew context:observeContext];
[super awakeFromNib];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test)];
[self addGestureRecognizer:tap];
[self createCircles];
}
- (void)test
{
DDLogVerbose(@"got tapped");
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
DDLogVerbose(@"something got in here");
if ([keyPath isEqualToString:@"gestureRecognizers"]) {
DDLogVerbose(@"ThreeCirclesView got a gesture recognizer");
}
}
However, it's not working. Am I doing this right? Or is the property gestureRecognizers
not KVO-able?