上下抖动的进度条

#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;

}

时间: 2024-08-05 06:35:19

上下抖动的进度条的相关文章

Android 从无到有打造一个炫酷的进度条效果

从无到有打造一个炫酷的进度条效果

每周进度条(第十五周)

第十五周进度条   第十五周 所花时间 1h 代码量(行)  100 博客量(篇)  1 学到的知识 对图片的处理 在Android程序中加入图片

Bootstrap进度条

Bootstrap 进度条使用 CSS3 过渡和动画来获得该效果.Internet Explorer 9 及之前的版本和旧版的 Firefox 不支持该特性, Opera 12 不支持动画. 默认的进度条 创建一个基本的进度条的步骤如下: 添加一个带有 class .progress 的 <div>. 接着,在上面的 <div> 内,添加一个带有 class .progress-bar 的空的 <div>. 添加一个带有百分比表示的宽度的 style 属性,例如 sty

HTML5/CSS3超酷进度条 不同进度多种颜色

下面我们来看看实现这款进度条的过程和源码,代码主要由HTML.CSS以及jQuery组成,实现过程也相对比较简单.HTML代码: <div id="wrapper">     <div class="loader-container">           <div class="meter">0</div>           <span class="runner"&g

基于HT for Web矢量实现HTML5文件上传进度条

在HTML中,在文件上传的过程中,很多情况都是没有任何的提示,这在体验上很不好,用户都不知道到时有没有在上传.上传成功了没有,所以今天给大家介绍的内容是通过HT for Web矢量来实现HTML5文件上传进度条,矢量在<矢量Chart图表嵌入HTML5网络拓扑图的应用>一文中已经讲述了关于setCompType()方法的应用,今天我们用setImage()方法充分利用系统中定义好的矢量资源来实现文件上传进度条,我们先来看下效果图: 从效果图可以看到,向服务器上传了一个mp4文件,并在最下方显示

Android的下拉刷新带进度条效果

首先看一下运行效果图,程序的下拉刷新参考了视频,在视频页面也提供了源码下载, http://www.imooc.com/learn/135 本篇主要说在此基础上增加了进度条的快速旋转和递增递减处理,在文章最后也会给出源码,这里主要描述一下所用的一个类 RoundProgressBar package com.cayden.listview; import android.content.Context; import android.content.res.TypedArray; import

【WebView】带加载进度条的WebView及Chrome联调

先看效果图: 看到顶部蓝色的进度条了. 原理:用到了 android.webkit.WebChromeClient中的onProgressChanged,而android.webkit.WebViewClient是没有这个方法的.所以普通的WebView是无法实现进度条的. 下面直接上干货: /** * ProgressWebView * * @author lif * * */ @SuppressWarnings("deprecation") public class Progres

OpenCV GUI基本操作,回调函数,进度条,裁剪图像等

代码为转载,出处找不到了,不贴了 工具条进度条: // ConvertColor.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #pragma comment(lib,"opencv_core2410d.l

python 进度条

功能说明:将程序的执行进展情况按照百分比用进度条显示. print:打印末尾会自动加上换行符'\n',如果要让打印的结果一直在同一行显示,不能使用这个命令 sys.stdout.write():打印输出但结尾不带'\n',使输出一直在同一行,同时在末尾加上行首符'\r',将最新的输出结果一直保持在行首 sys.stdout.flush():将缓存在sys.stdout.write()的内容暂时打印出来 #!/usr/bin/env python # -*- coding:utf-8 -*- im