CABasicAnimation - 上下滑动动画
#import <UIKit/UIKit.h> @interface TJProgressView : UIView
@property(nonatomic,assign)CGFloat progressValue;
- (void)showInView:(UIView *)baseView;
@end
//
// TJProgressView.m
// CurveProgressDemo
//
// Created by MJ on 15/6/12.
// Copyright (c) 2015年 SNWFMJ. All rights reserved.
// #import "TJProgressView.h"
#define kContainerViewSize CGSizeMake(30.f, 25.f)
#define kPadding 5.f
@interface TJProgressView ()
{
UIView *leftView;
UIView *middleView;
UIView *rightView;
UIView *containerView; }
@end
@implementation TJProgressView
- (instancetype)init
{
if (self = [super init])
{
[self setUp];
}
return self;
}
- (void)setUp
{
containerView = [[UIView alloc ]init];
containerView.translatesAutoresizingMaskIntoConstraints = NO;
containerView.backgroundColor = [UIColor clearColor];
[self addSubview:containerView];
NSArray *containerView_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[containerView]|" options: metrics:nil views:NSDictionaryOfVariableBindings(containerView)];
NSArray *containerView_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[containerView]|" options: metrics:nil views:NSDictionaryOfVariableBindings(containerView)];
[self addConstraints:containerView_H];
[self addConstraints:containerView_V]; [self test]; }
- (void)test
{
leftView = [[UIView alloc]init];
leftView.translatesAutoresizingMaskIntoConstraints = NO;
leftView.backgroundColor = [UIColor yellowColor];
[containerView addSubview:leftView];
NSArray *leftView_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[leftView]|" options: metrics:nil views:NSDictionaryOfVariableBindings(leftView)];
[containerView addConstraints:leftView_V]; middleView = [[UIView alloc]init];
middleView.translatesAutoresizingMaskIntoConstraints = NO;
middleView.backgroundColor = [UIColor redColor];
[containerView addSubview:middleView];
NSArray *middleView_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[middleView]|" options: metrics:nil views:NSDictionaryOfVariableBindings(middleView)];
[containerView addConstraints:middleView_V]; rightView = [[UIView alloc]init];
rightView.translatesAutoresizingMaskIntoConstraints = NO;
rightView.backgroundColor = [UIColor blueColor];
[containerView addSubview:rightView];
NSArray *rightView_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[rightView]|" options: metrics:nil views:NSDictionaryOfVariableBindings(rightView)];
[containerView addConstraints:rightView_V];
NSDictionary *dic_paddingConstraint = @{
@"padding":@(kPadding) };
NSArray *allView_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[leftView]-padding-[middleView(leftView)]-padding-[rightView(middleView)]-0-|" options: metrics:dic_paddingConstraint views:NSDictionaryOfVariableBindings(leftView,middleView,rightView)];
[containerView addConstraints:allView_H]; }
- (void)showInView:(UIView *)baseView
{
NSDictionary *dic_selfConstraint = @{
@"height":@(kContainerViewSize.height),
@"width":@(kContainerViewSize.width) };
self.translatesAutoresizingMaskIntoConstraints = NO;
[baseView addSubview:self]; NSLayoutConstraint *self_CenterX = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:baseView attribute:NSLayoutAttributeCenterX multiplier: constant:];
NSLayoutConstraint *self_CenterY = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:baseView attribute:NSLayoutAttributeCenterY multiplier: constant:]; NSArray *self_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[self(width)]" options: metrics:dic_selfConstraint views:NSDictionaryOfVariableBindings(self)];
NSArray *self_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[self(height)]" options: metrics:dic_selfConstraint views:NSDictionaryOfVariableBindings(self)]; [baseView addConstraints:@[self_CenterX,self_CenterY]];
[baseView addConstraints:self_H];
[baseView addConstraints:self_V]; }
- (void)setProgressValue:(CGFloat)progressValue
{
_progressValue = progressValue; [self addAnimation:containerView.layer progressValue:_progressValue]; }
- (void)addAnimation:(CALayer *)layer progressValue:(CGFloat)value
{
CABasicAnimation *leftAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
leftAnimation.fromValue =@;
leftAnimation.toValue = @(value*kContainerViewSize.height);
leftAnimation.repeatCount = MAXFLOAT;
leftAnimation.duration = 0.5f; [layer addAnimation:leftAnimation forKey:@"test"];
} @end //
// ViewController.m
// CurveProgressDemo
//
// Created by MJ on 15/6/12.
// Copyright (c) 2015年 SNWFMJ. All rights reserved.
// #import "ViewController.h"
#import "TJProgressView.h"
@interface ViewController ()
{
TJProgressView *progressView;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; progressView = [[TJProgressView alloc]init];
[progressView showInView:self.view]; [NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(changeValue) userInfo:nil repeats:YES]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; }
- (void)changeValue
{
progressView.progressValue =0.5;
}
@end
CABasicAnimation - 上下滑动动画的更多相关文章
- jQuery实用小技巧-获取选中的的下拉框和返回头部滑动动画
//获取选中的下拉框 $('#someElement').find('option:selected'); $('#someElement option:selected'); //返回头部滑动动画 ...
- Android滑动动画ViewFlipper和视频播放VideoView的使用
Android滑动动画,可以用ViewPager或者ViewFlipper实现. ViewPager自带触摸滑动功能,结合Fragment使用很好,来自补充组件android-support-v4.j ...
- 利用jquery实现百度新闻导航菜单滑动动画
前言 前两天,群里有人问百度新闻导航是如何实现的,当时由于忙于工作,没有来得及细看,恰好今天有空闲时间,索性就实现一下这个效果吧: 思路与步骤 1.利用UL创建简单横向导航: <!DOCTYPE ...
- viewpager处理(二):设置当前item时,让viewpager不出现滑动动画
我们在使用viewpager.setCurrentItem(position);的时候,viewpager出现滑动动画,如何去掉这个动画呢? 可以用viewpager.setCurrentItem(p ...
- android仿微信红包动画、Kotlin综合应用、Xposed模块、炫酷下拉视觉、UC浏览器滑动动画等源码
Android精选源码 仿微信打开红包旋转动画 使用Kotlin编写的Android应用,内容你想象不到 Android手机上的免Root Android系统日志Viewer 一个能让微信 Mater ...
- 【Web】利用jquery实现百度新闻导航菜单滑动动画
前言 前两天,群里有人问百度新闻导航是如何实现的,当时由于忙于工作,没有来得及细看,恰好今天有空闲时间,索性就实现一下这个效果吧: 思路与步骤 1.利用UL创建简单横向导航: <!DOCTYPE ...
- JQuery--基础动画、滑动动画、淡入淡出动画、自定义动画
/** * [JQ基础动画] * show() 显示 * hide() 隐藏 * toggle() 切换 * 默认无动画,如果要产生动画 * 在括号内,添加毫秒数,可产生动画和控制动画的快慢 * * ...
- Android的Activity屏幕切换滑动动画
Activity的切换效果使用的是Android的动画效果,Android的动画在官方有相关资料:http://developer.android.com/guide/topics/graphics/ ...
- jQuery
代码的层定位滑动动画效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- MongoDB主库和从库的数据大小不一致原因判断
1. 环境(MongoDB的版本是3.2.16) [root@xxx-mongodb-primary ~]# cat /etc/redhat-release CentOS Linux release ...
- Linux 环境下安装python相关
目录 Linux 环境下安装python相关 linux软件包管理工具之yum工具(如同pip3工具) yum源理解 下载阿里云的.repo仓库文件 ,放到/etc/yum.repos.d/ yum安 ...
- 51nod1103 N的倍数
[题解] 先预处理出模N意义下的前缀和sum[i]. 1.如果sum[i]=0,那么1~i的数之和就是N的倍数 2.sum[i]%N总共有0~N-1这N种情况:根据1,如果sum[i]为0则必定有解: ...
- 【Codeforces 340D】Bubble Sort Graph
[链接] 我是链接,点我呀:) [题意] 让你根据冒泡排序的规则 建立一张图 问你这张图的最大独立子集的大小 [题解] 考虑a[i]会和哪些点连边? 必然是在a[i]左边且比它大的数字以及在a[i]右 ...
- 【codeforces 766E】Mahmoud and a xor trip
[题目链接]:http://codeforces.com/contest/766/problem/E [题意] 定义树上任意两点之间的距离为这条简单路径上经过的点; 那些点上的权值的所有异或; 求任意 ...
- oracle 增量备份恢复策略(基础知识)
EXP和IMP是Oracle提供的一种逻辑备份工具.逻辑备份创建数据库对 象的逻辑拷贝并存入一个二进制转储文件.这种逻辑备份需要在数据库启动的情况下使用, 其导出实质就是读取一个数据库记录集(甚至可以 ...
- 清北学堂模拟赛d3t6 c
分析:比较神奇的一道题.要把树变成环肯定要先变成链,然后把链给拼接成环.接下来考虑一个脑洞大开的树形dp:设f[i][0]表示i不与父节点相连的链数,f[i][1]表示i与父节点相连的链数,先考虑怎么 ...
- Element 'dependencies' cannot have character[children],because the type's content type is elemen
问题描述: Element 'xxxxxxx' cannot have character [children],because the type's content type is element- ...
- MySql解压版使用
1.解压 2.配置环境变量 3.新建空目录data,修改ini配置文件,修改basedir和datadir 4.管理员运行cmd,进入bin目录 5.mysql -install,如果提示错误,先my ...
- 线段树+离线 hdu5654 xiaoxin and his watermelon candy
传送门:点击打开链接 题意:一个三元组假设满足j=i+1,k=j+1,ai<=aj<=ak,那么就好的.如今告诉你序列.然后Q次询问.每次询问一个区间[l,r],问区间里有多少个三元组满足 ...