zoukankan      html  css  js  c++  java
  • 上下抖动的进度条

    #import <UIKit/UIKit.h>
    
    @interface TJShakeProgressView : UIView
    
    
    @property(nonatomic,assign)CGFloat progress;
    
    
    @end

    //

    //  TJShakeProgressView.m

    //  TJShakeProgressView

    //

    //  Created by MJ on 15/7/6.

    //  Copyright (c) 2015 TJ. All rights reserved.

    //

     

    #import "TJShakeProgressView.h"

     

    @interface TJShakeProgressView ()

    {

        UIView *firstView;

        UIView *secondView;

        UIView *thirldView;

        UIView *fourView;

        UIView *contentView;

        NSMutableArray *viewArray;

        NSInteger  count;

        CGFloat temp;

    }

    @end

     

    @implementation TJShakeProgressView

     

    - (void)awakeFromNib

    {

        [super awakeFromNib];

        

        [self setUp];

        

    }

    - (void)setUp

    {

        contentView = [[UIView alloc]init];

        contentView.translatesAutoresizingMaskIntoConstraints = NO;

        contentView.backgroundColor = [UIColor clearColor];

        firstView = [[UIView alloc]init];

        secondView = [[UIView alloc]init];

        thirldView = [[UIView alloc]init];

        fourView = [[UIView alloc]init];

        [self addSubview:contentView];

        NSArray *contentView_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(contentView)];

         NSArray *contentView_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[contentView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(contentView)];

        [self addConstraints:contentView_H];

        [self addConstraints:contentView_V];

      

        

       viewArray = [NSMutableArray arrayWithArray:@[firstView,secondView,thirldView,fourView]];

        

        for (UIView *views in viewArray)

        {

          

            views.backgroundColor  = [UIColor colorWithRed:arc4random()%255/256.f green:arc4random()%255/256.f blue:arc4random()%255/256.f alpha:1.f];

            views.translatesAutoresizingMaskIntoConstraints = NO;

            [contentView addSubview:views];

            

            NSLayoutConstraint *constraint_Bottom = [NSLayoutConstraint constraintWithItem:views attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:contentView attribute:NSLayoutAttributeBottom multiplier:1.f constant:0.f];

            [contentView addConstraint:constraint_Bottom];

        }

        

     

        NSArray *allView_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[firstView]-[secondView(firstView)]-[thirldView(secondView)]-[fourView(thirldView)]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(firstView,secondView,thirldView,fourView)];

        [contentView addConstraints:allView_H];

        

     

    }

    - (void)setProgress:(CGFloat )progress

    {

        

        if (progress<0.f) {

            _progress = 0.0f;

        }

        else if (progress<=1.0f)

        {

            _progress = progress;

        }

        else

        {

          _progress = 1.f;

        }

        for (UIView *views in viewArray)

        {

            count++;

            temp = count%2?0.75:0.45;

            [views needsUpdateConstraints];

            NSLayoutConstraint *constraint_Height = [NSLayoutConstraint constraintWithItem:views attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:contentView attribute:NSLayoutAttributeHeight multiplier:(_progress*temp) constant:0.f];

            [contentView addConstraint:constraint_Height];

             [views layoutIfNeeded];

            CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"position.y"];

            basic.toValue = @(_progress*contentView.bounds.size.height);

            basic.repeatDuration = MAXFLOAT;

            basic.duration = 0.60f;

            basic.autoreverses= YES;

            [views.layer addAnimation:basic forKey:@"test"];

          

           

        }

        

    }

     

    @end

    #import "ViewController.h"
    #import "TJShakeProgressView.h"
    @interface ViewController ()
    @property (weak, nonatomic) IBOutlet TJShakeProgressView *progressView;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
      
        
         _progressView.progress = 0.81;
    
    }

  • 相关阅读:
    LINQ分组排序后获取每组第一条记录
    String 中的Trim
    C# Switch优雅写法
    C# 输入指定日期获取当前年的第一天 、当前年的最后天、某月的第一天 、某月的最后一天
    快捷方式 ABP——切换MySQL数据库
    新建立git分支,之后将分支合并到master上
    C# Contains()、 == 和Equals() 比较
    使用TimeSpan 日期与时间拼接
    ActiveReports报表行号
    iOS基础(八)——最新更新方法,每天只提示一次
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4628552.html
Copyright © 2011-2022 走看看