Modular Design and animation modular design in animation
1. Determine the difficulty of animation effect implementation 2. Split the animation effect into small modules 3. Combine the written small modules into the animation effect you need
1. Create a BaseAnimationView master class.
@ Interface BaseAnimationView: UIView
-(Void) show;
-(Void) hide;
-(Void) buildView;
@ End
# Import "BaseAnimationView. h"
# Import "CircleView. h"
# Import "LineView. h"
@ Interface BaseAnimationView ()
@ Property (nonatomic, strong) CircleView * circleView;
@ Property (nonatomic, strong) RectView * lineView;
@ End
@ Implementation BaseAnimationView
-(Void) show {
[Self. circleViewshow];
[Self. lineViewshow];
}
-(Void) hide {
[Self. circleViewhide];
[Self. lineViewhide];
}
-(Void) buildView {
Self. circleView = [[CircleViewalloc] initWithFrame: CGRectZero];
[SelfaddSubview: self. circleView];
Self. lineView = [[RectViewalloc] initWithFrame: CGRectZero];
[SelfaddSubview: self. lineView];
}
@ End
2. Create a CircleView, LineView class, and method names. These two classes are controlled by BaseAnimationView.
@ Interface CircleView: UIView
-(Void) show;
-(Void) hide;
-(Void) buildView;
@ End
# Import "CircleView. h"
@ Implementation CircleView
-(Void) show {}
-(Void) hide {}
-(Void) buildView {}
@ End
@ Interface LineView: UIView
-(Void) show;
-(Void) hide;
-(Void) buildView;
@ End
# Import "LineView. h"
@ Implementation LineView
-(Void) show {}
-(Void) hide {}
-(Void) buildView {}
@ End
3. Complicated animations are written into the BaseAnimationView. unnecessary details are not exposed for maintenance.
-(Void) viewDidLoad {
[SuperviewDidLoad];
// Complex animations are written into the BaseAnimationView without exposing unnecessary details.
BaseAnimationView * baseView = [[BaseAnimationViewalloc] initWithFrame: CGRectZero];
[Self. viewaddSubview: baseView];
[BaseViewshow];
}
Iv. Summary 1. develop a unified animation interface 2. principle of High Cohesion and low coupling in animation 3. precautions for designing animation functions 4. use the Li's replacement principle to deal with the inheritance of the animation class 5. modular Design in animation
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.