3

I am using observer following code

myView = [[UIView alloc] initWithFrame:CGRectZero];
[myView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];

Another Code

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSLog(@"observeValueForKeyPath");
    if([keyPath isEqualToString:@"frame"]) 
    {
        [self layoutViews];
    }
}

but I never got the Log observeValueForKeyPath

Amit Battan
  • 2,968
  • 2
  • 32
  • 68
  • 1
    Interesting question and I don't know the answer, but as far as what you are trying to accomplish, there are more efficient ways. You should use setNeedsLayout and let the rendering system do the dirty work for you on the next turn of the runloop. – D.C. Oct 18 '11 at 08:22
  • I tried your code now, and observeValueForKeyPath is getting called correctly. Are you sure that myView is not release somewhere? How are you updating the frame; code, autoresizing on orientation change, etc.? – adamsiton Oct 23 '11 at 16:51
  • yes .. actually I have two sample of code on is totally native which working fine.. and other is as a phonegap plugin which is not working https://github.com/gdavis/FGallery-iPhone/issues/6 – Amit Battan Oct 24 '11 at 05:15

1 Answers1

1

UIKit isn't consistently KVO-compliant, and you shouldn't take it for granted that properties on UIKit classes are ever KVO-compliant, even if they seem to be through experimentation.

See also: iOS: How do I know if a property is KVO-compliant?

Community
  • 1
  • 1
Joshua Pokotilow
  • 1,213
  • 9
  • 13