1.动画效果实现难度的判断
2.将看到的动画效果拆分成小模块
3.将写好的小模块组合成你所需要的动画效果
一,新建一个BaseAnimationView主控类
@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.circleView
show];
[self.lineView
show];
}
- (void)hide {
[self.circleView
hide];
[self.lineView
hide];
}
- (void)buildView {
self.circleView = [[CircleView
alloc]
initWithFrame:CGRectZero];
[self
addSubview:self.circleView];
self.lineView = [[RectView
alloc] initWithFrame:CGRectZero];
[self
addSubview:self.lineView];
}
@end
二、新建CircleView,LineView类,方法名都统一,此两类被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
三、使用复杂的动画被写进了BaseAnimationView当中,没有暴露不必要的细节,便于维持
- (void)viewDidLoad {
[super
viewDidLoad];
//
复杂的动画被写进了BaseAnimationView当中,没有暴露不必要的细节
BaseAnimationView *baseView = [[BaseAnimationView
alloc]
initWithFrame:CGRectZero];
[self.view
addSubview:baseView];
[baseView
show];
}
四、总结
1.制定统一的动画接口
2.动画中的高内聚低耦合原理
3.设计动画函数的注意事项
4.用里氏代换原则来处理动画类的继承问题
5.动画中的模块化设计
版权声明:本文为博主原创文章,未经博主允许不得转载。