偶然遇到一个需求:可缩放,二级刻度可显隐。

 

两个思路: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];
                }
            }
        }
    }
}

 

草率的记录一下,欢迎斧正!

相关文章:

  • 2021-12-25
  • 2022-12-23
  • 2021-06-30
  • 2021-10-15
  • 2021-06-13
  • 2021-08-23
  • 2021-12-16
  • 2022-12-23
猜你喜欢
  • 2021-05-12
  • 2021-10-09
  • 2022-12-23
  • 2022-02-15
  • 2021-08-09
  • 2021-08-31
  • 2021-09-03
相关资源
相似解决方案