偶然遇到一个需求:可缩放,二级刻度可显隐。
两个思路:1.所有的刻度都画出来,根据缩放比例控制二级刻度的显隐。理论上会流畅些。
2.开始只展示一级刻度,当缩放比例超过某个级别时候,添加子刻度。
这里尝试了第二条,效果还可以。贴上主要代码:
-(void)layoutSubviews { [super layoutSubviews]; for (UIView *view in self.subviews) { if (1024 == view.tag) { [view removeFromSuperview]; } } for (NSInteger i = 0; i < _count; i++) { UIView *sign = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 6, 6)]; sign.tag = 1024; sign.backgroundColor = [UIColor redColor]; CGPoint center = CGPointMake(i * self.frame.size.width / _count, self.frame.size.height / 2); sign.center = center; // sign.layer.cornerRadius = 3; // sign.clipsToBounds = YES; [self addSubview:sign]; if (self.width > _originLength * 10) { if (i < _count) { for (NSInteger j = 0; j < 10; j++) { UIView *sign = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 4, 4)]; sign.tag = 1024; sign.backgroundColor = [UIColor redColor]; CGPoint center = CGPointMake(i * self.frame.size.width / _count + j * self.frame.size.width / _count / 10, self.frame.size.height / 2); sign.center = center; sign.layer.cornerRadius = 2; sign.clipsToBounds = YES; [self addSubview:sign]; } } } } }
草率的记录一下,欢迎斧正!