Should a UIViewController control a UIView's animations?

animation, ios, model-view-controller, objective-c, uiview

Solution

Based on your description, you can legitimately do them in either place because the animation does not depend on your application's model. If, however, the animation depended on data from your model, then the controller should perform the animation because the controller sees the model data (but the view does not).

Problem

I've been pushing myself to learn more MVCS styled programming and am attempting to organize my code better. My main question, is I have a UIViewController that brings up a view when an event occurs. When the view is created and when the view is destroyed, I'd like to run some animations on the view appearing and disappearing. I can do this both in the UIView class I have and in the UIViewController. Once these animations have been established, they do not need to be changed. Should I do this within the UIViewController or the UIView to stay MVC compliant? The code is currently in my UIView as such: ``` - (IBAction)removeView { NSLog(@"Remove"); if (self.completionBlock != nil) { [UIView animateWithDuration:1.0f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ self.transform = CGAffineTransformMakeTranslation(self.frame.origin.x, self.frame.origin.y - self.superview.frame.size.height); self.alpha = 0; // also fade to transparent }completion:^(BOOL finished) { if (finished) { [self removeFromSuperview]; } }]; self.completionBlock(YES); } } ```

Original source