Might not solve your problem with animating. But you should remove your observer from the object before the object is deallocated. That would make the exception go away. i.e in this case you should
[self.scrollView.documentView removeObserver:self forKeyPath:@"bounds.size"]
;
[self.scrollView.documentView removeObserver:self forKeyPath:@"frame"]
This should be done before self.scrollView.documentView goes out of memory. Considering that can be tricky, you could try adding observer like this:
[self addObserver:self forKeyPath:@"self.scrollView.documentView.bounds.size" options:NSKeyValueObservingOptionNew context:Nil];
[self addObserver:self forKeyPath:@"self.scrollView.documentView.frame" options:NSKeyValueObservingOptionNew context:Nil];
Another thing, i remember reading somewhere is, observing the frame or bounds, is generally not considered a good Idea, but I'm not sure about this.
EDIT: Considering other answer: "bounds.size
" won't work since since size
is not set directly using any setter method. So instead, observe the frame and extract the size information from it.
(For UIView only frame is observable and not bounds. I guess the same applies for NSView)