我一直在推動自己學習更多MVCS風格的編程,並試圖更好地組織我的代碼。我的主要問題是,我有一個UIViewController,當事件發生時調出一個視圖。當視圖被創建並且視圖被銷燬時,我想在視圖上運行一些動畫並且消失。我可以在UIView類和UIViewController中做到這一點。一旦這些動畫已經建立,他們不需要改變。我應該在UIViewController或UIView中做到這一點,以保持MVC兼容?UIViewController應該控制UIView的動畫嗎?
的代碼是目前在我UIView這樣:
- (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);
}
}