基本动画效果(点赞,长按抖动,播放器转盘,水滴效果)
定义属性
- (IBAction)trainsformAction:(id)sender;@property(nonatomic,retain)UIImageView *imageView;
@property(nonatomic,assign)BOOL isRotation;
@property(nonatomic,retain)UIImageView *secImageView;
@property(nonatomic,retain)UIButton *button;
@property(nonatomic,assign)BOOL isSelect;
@property(nonatomic,retain)UIButton *goodButton;
@property(nonatomic,retain)UIView *myView;
创建
self.imageView=[[UIImageView alloc] initWithFrame:CGRectMake(100, 200, 200, 200)];self.imageView.layer.cornerRadius=100;self.imageView.layer.masksToBounds=YES;[self.view addSubview:self.imageView];self.imageView.image=[UIImage imageNamed:@"c2.jpg"];//用户交互打开self.imageView.userInteractionEnabled=YES;
1. 音乐播放器转啊转
//layer动画(音乐播放器转啊转)//控件可以拆分成两部分,一部分是控件的样式,比如边框,文字等,这些都是通过操作控件layer层来完成的,另一部分是控件的功能,比如button点击方法,这些都是自己的功能//layer动画主要是给控件layer层添加动画来实现效果//参数需要指定修改的是哪个属性CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];//设置动画起始的值animation.fromValue=[NSNumber numberWithFloat:0];//设置最终旋转的角度animation.toValue=[NSNumber numberWithFloat:M_PI*2];//缩放 (把上面三行注掉换成缩放,动画就由转转变成缩放)
// CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
// //起始缩放比例
// animation.fromValue=[NSNumber numberWithInt:1];
// animation.toValue=[NSNumber numberWithInt:2];//设置动画的播放时长animation.duration=10;//设置动画执行次数,NSIntegerMax整数最大值animation.repeatCount=NSIntegerMax;//旋转之后是否回到原来位置animation.autoreverses=NO;//是否按照结束位置继续旋转animation.cumulative=YES;//把动画加到imageview的layer上[self.imageView.layer addAnimation:animation forKey:@"rotate"];//给imageview上添加一个轻点的手势UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];[self.imageView addGestureRecognizer:tap];self.isRotation=NO;
旋转的实现方法(暂停和播放)
-(void)tapAction:(UITapGestureRecognizer *)tap{if (self.isRotation==NO) {//每一个view的layer层系统都有一个记录时间的属性,通过改变view的动画时间来控制动画效果//获取播放旋转的时间点CFTimeInterval stop=[self.imageView.layer convertTime:CACurrentMediaTime() fromLayer:nil];//为了暂停,把播放速度设置为0self.imageView.layer.speed=0;//记录当前时间的偏移量self.imageView.layer.timeOffset=stop;}else{//先找到上一次停止的时间偏移量CFTimeInterval time=self.imageView.layer.timeOffset;//让动画旋转的速度恢复self.imageView.layer.speed=1;//把偏移量清零self.imageView.layer.timeOffset=0;self.imageView.layer.beginTime=0;//接下来以停止时间作为开始,继续旋转self.imageView.layer.beginTime=[self.imageView.layer convertTime:CACurrentMediaTime() fromLayer:nil]-time;}//状态取反self.isRotation=!self.isRotation;
}
2. 系统的多种动画效果
self.secImageView=[[UIImageView alloc] initWithFrame:CGRectMake(70, 450, 200, 200)];[self.view addSubview:self.secImageView];self.secImageView.image=[UIImage imageNamed:@"c2.jpg"];self.button=[UIButton buttonWithType:UIButtonTypeSystem];self.button.frame=CGRectMake(300, 450, 50, 50);self.button.backgroundColor=[UIColor cyanColor];[self.view addSubview:self.button];[self.button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
点击方法
-(void)click:(UIButton *)button{CATransition *transition=[CATransition animation];//设置动画类型transition.type=@"pageCurl";/** type** 各种动画效果 其中除了'fade', `moveIn', `push' , `reveal' ,其他属于私有的API.* ↑↑↑上面四个可以分别使用'kCATransitionFade', 'kCATransitionMoveIn', 'kCATransitionPush', 'kCATransitionReveal'来调用.* @"cube" 立方体翻滚效果* @"moveIn" 新视图移到旧视图上面* @"reveal" 显露效果(将旧视图移开,显示下面的新视图)* @"fade" 交叉淡化过渡(不支持过渡方向) (默认为此效果)* @"pageCurl" 向上翻一页* @"pageUnCurl" 向下翻一页* @"suckEffect" 收缩效果,类似系统最小化窗口时的神奇效果(不支持过渡方向)* @"rippleEffect" 滴水效果,(不支持过渡方向)* @"oglFlip" 上下左右翻转效果* @"rotate" 旋转效果* @"push"* @"cameraIrisHollowOpen" 相机镜头打开效果(不支持过渡方向)* @"cameraIrisHollowClose" 相机镜头关上效果(不支持过渡方向)*///设置动画时长transition.duration=3;//设置动画播放次数transition.repeatCount=NSIntegerMax;[self.secImageView.layer addAnimation:transition forKey:@"transition"];}
3. 长按抖动
//长按抖动self.myView=[[UIView alloc] initWithFrame:CGRectMake(110, 140, 160, 50)];self.myView.backgroundColor=[UIColor redColor];[self.view addSubview:self.myView];UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];[self.myView addGestureRecognizer:longPress];
点击方法
-(void)longPress:(UILongPressGestureRecognizer *)longPress{//关键帧动画CAKeyframeAnimation *keyAnimation=[CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];float top=M_PI/20;float bom=M_PI/20;keyAnimation.values=@[@(top),@(0),@(bom),@(0),@(top)];//设置动画时长keyAnimation.duration=0.1;//次数keyAnimation.repeatCount=NSIntegerMax;[self.myView.layer addAnimation:keyAnimation forKey:@"key"];//停止动画//dispatch_after的作用就是会延迟执行内容dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{//在block里写停止动画的方法[self.myView.layer removeAnimationForKey:@"key"];});}
4. 点赞效果
self.goodButton=[UIButton buttonWithType:UIButtonTypeCustom];self.goodButton.frame=CGRectMake(300, 70, 50, 50);[self.view addSubview:self.goodButton];[self.goodButton addTarget:self action:@selector(changeImage:) forControlEvents: UIControlEventTouchUpInside];[self.goodButton setBackgroundImage:[UIImage imageNamed:@"IconGood.png"] forState:UIControlStateNormal ];//把button自带的点击效果取消,button的类型要设置成customself.goodButton.adjustsImageWhenHighlighted=NO;self.isSelect=NO;
点击实现
-(void)changeImage:(UIButton *)button{//关键帧动画//用动画完成放大的效果CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];//需要给他设置一个关键帧的值,这个值就是变化过程//values是一个数组animation.values=@[@(0.5),@(1.0),@(1.5)];//设置动画的时长animation.duration=0.2;//加到button上[self.goodButton.layer addAnimation:animation forKey:@"animation"];//根据状态更换图片if (self.isSelect == NO) {[self.goodButton setBackgroundImage:[UIImage imageNamed:@"IconHgood.png"] forState:UIControlStateNormal];}else{[self.goodButton setBackgroundImage:[UIImage imageNamed:@"IconGood.png"] forState:UIControlStateNormal];}self.isSelect=!self.isSelect;}
基本动画效果(点赞,长按抖动,播放器转盘,水滴效果)相关推荐
- Android 自定义控件 仿MX 播放器的SeekBar效果
一.分析 最近下载了个MX 播放器来看视频,发现他的SeekBar做的挺有趣的,先看看MX 播放器的SeekBar效果: 外面多了个框框,没有了进度的那个小圆点,还可以以水平方向的摆放和竖直方向的摆放 ...
- HTML5播放器调用(功能效果)
播放器调用 <div id="player"></div> <script src="//player.polyv.net/script/ ...
- 卡拉OK效果的实现-iOS音乐播放器
自己编写的音乐播放器偶然用到这个模块,发现没有思路,而且上网搜了搜,关于这方面的文章不是很多,没找到满意的结果,然后自己也是想了想,最终实现了这种效果,想通了发现其实很简单. 直接上原理: 第一种: ...
- 播放器实现声音效果淡入淡出
目录 1.前言 2.基本代码 3.延伸思考问题 4.开始播放-淡入 5.停止播放-淡出 6.完整基本代码修改 1.前言 由于切歌会有爆破音的问题.方案有很多,比如音频合成淡入淡出fadein,fade ...
- iOS实现基于VLC播放器的封装效果
前言: 在一些特定场景下,我们获取到的音视频,由于格式比较特殊,用avplayer等播放器是无法播放的,此时,我们可以借助强大的VLC播放器来处理. 原理这里不再赘述,下面我们讲一下如何添加VLC播放 ...
- 使用windowManager实现音乐播放器(悬浮框)效果
在使用要获取CompatModeWrapper,首先得在应用程序的AndroidManifest.xml文件中添加权限 <uses-permission android:name="a ...
- C# 粘连窗体效果(窗体连动 类似千千静听播放器的)
两个窗体分别是FormMain FormList 第1个窗体:FormMain : public partial class FormMain : Form { FormList formlist=n ...
- Qt图片定时滚动播放器+透明过渡动画
目录 参考 结构 PicturePlay.pro main.cpp myqlabel.h 自定义QLabel myqlabel.cpp自定义QLabel pictureplay.h picturepl ...
- 微信小程序——【云音乐播放器】
目录 第一章 开发准备 一.项目结构 二.新建微信小程序项目 第二章 标签页切换 一.常用组件介绍 二.编写页面结构和样式 第三章 音乐推荐 一.组件介绍 二.编写音乐推荐页面结构和样式 第四章 播放 ...
最新文章
- 苏宁零售云 App 稳定保障实践
- JVM:StringTable
- java多线程系列(四)---ReentrantLock的使用
- Fiddler本机调试的方法
- 147. Insertion Sort List
- 用计算机模仿真实系统的技术叫,计算机模拟技术.pdf
- can not find Artifact XXX 的原因
- 风控模型面试问题汇总
- Win_Server_2003-2016_加密勒索事件必打补丁合集
- Linux 卸载Mysql
- Java开发快递物流项目(7)
- matlab 超像素合并,超像素区域合并
- 【theano-windows】学习笔记五——theano中张量部分函数
- 背景色透明度影响字体的透明度
- PM Interview 60quiz
- matlab中sl设置频率为95khz,BOOST电路设计及matlab仿真
- visio 2007 画直线和矩形
- 电动葫芦断火限位器安装接线电路图
- 物联网之父凯文-阿什顿:物联网世界充斥着人工智能
- 深度技术GHOST WIN7 SP1 2013 新春版