Reputation: 2997
I used KVO to observe changes in a frame and set another frame accordingly
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context{
if ([keyPath isEqualToString:KeyPathForFrameBeingObserved]) {
[UIView animateWithDuration:1 animations:^{
CGRect frame = [self playWithFrame:viewBeingMonitored.frame];
self.viewToAnimate.frame = frame;
}];
}
}
Code in the animation block is executed but animation is not working, I suspected that repeated calls to animation method could cause this but using log messages I found that animation is not working even for a single call, can anyone explain that ?
iPad 2/(iOS8.4)
dispatch_async(dispatch_get_main_queue(), ^{ ... });
but animation still not working.dispatch_after
to run it only using the last element in the queue to avoid repeated calls but didn't work.Upvotes: 0
Views: 285
Reputation: 1
This is an older question but I thought I would answer in case someone else is reading this. You will need to call setFrame to set the frame of the animation instead of the simple assignment.
CGRect frame = [self playWithFrame:viewBeingMonitored.frame]; [self.viewToAnimate setFrame:frame];
Upvotes: 0
Reputation: 2837
It seems like you're trying to observe the property of an UIKit object. Keep in mind that:
... the classes of the UIKit framework generally do not support KVO ...
Source: https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/KVO.html
So, you have to check if your observeValueForKeyPath:ofObject:change:context:
is calling in fact.
Upvotes: 1