iOS tabbar点击动画效果实现
正常情况下,我们点击tabbar都只有一个变色效果,但有时候,如果我们想给它添加一个点击动画,该如何做呢?
先上几个效果图:
1、先放大,再缩小 2、Z轴旋转
3、Y轴位移 4、放大并保持
原理:利用UITabBarController实现,在tabbar的 didSelectItem 代理里添加动画效果。
下面就以上几种场景贴上代码:
准备代码:
@interface MainTabbarVC ()<UITabBarControllerDelegate>
@property (nonatomic,assign) NSInteger indexFlag; //记录上一次点击tabbar,使用时,记得先在init或viewDidLoad里 初始化 = 0
@end -(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
NSInteger index = [self.tabBar.items indexOfObject:item];
if (index != self.indexFlag) {
//执行动画
NSMutableArray *arry = [NSMutableArray array];
for (UIView *btn in self.tabBar.subviews) {
if ([btn isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
[arry addObject:btn];
}
}
//添加动画
//---将下面的代码块直接拷贝到此即可--- self.indexFlag = index;
}
}
1、先放大,再缩小
//放大效果,并回到原位
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//速度控制函数,控制动画运行的节奏
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.duration = 0.2; //执行时间
animation.repeatCount = ; //执行次数
animation.autoreverses = YES; //完成动画后会回到执行动画之前的状态
animation.fromValue = [NSNumber numberWithFloat:0.7]; //初始伸缩倍数
animation.toValue = [NSNumber numberWithFloat:1.3]; //结束伸缩倍数
[[arry[index] layer] addAnimation:animation forKey:nil];
2、Z轴旋转
//z轴旋转180度
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//速度控制函数,控制动画运行的节奏
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.duration = 0.2; //执行时间
animation.repeatCount = ; //执行次数
animation.removedOnCompletion = YES;
animation.fromValue = [NSNumber numberWithFloat:]; //初始伸缩倍数
animation.toValue = [NSNumber numberWithFloat:M_PI]; //结束伸缩倍数
[[arry[index] layer] addAnimation:animation forKey:nil];
3、Y轴位移
//向上移动
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
//速度控制函数,控制动画运行的节奏
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.duration = 0.2; //执行时间
animation.repeatCount = ; //执行次数
animation.removedOnCompletion = YES;
animation.fromValue = [NSNumber numberWithFloat:]; //初始伸缩倍数
animation.toValue = [NSNumber numberWithFloat:-]; //结束伸缩倍数
[[arry[index] layer] addAnimation:animation forKey:nil];
4、放大并保持
//放大效果
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//速度控制函数,控制动画运行的节奏
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.duration = 0.2; //执行时间
animation.repeatCount = ; //执行次数
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards; //保证动画效果延续
animation.fromValue = [NSNumber numberWithFloat:1.0]; //初始伸缩倍数
animation.toValue = [NSNumber numberWithFloat:1.15]; //结束伸缩倍数
[[arry[index] layer] addAnimation:animation forKey:nil];
//移除其他tabbar的动画
for (int i = ; i<arry.count; i++) {
if (i != index) {
[[arry[i] layer] removeAllAnimations];
}
}
此外,如果想定制其他动画效果,还可以从下面属性里自己定制动画
谢谢!~
iOS tabbar点击动画效果实现的更多相关文章
- Waves – 赞!超炫交互体验的点击动画效果
Waves 点击效果的灵感来自于谷歌的材料设计,很容易使用.只需要引入 waves.min.css 和 waves.min.js 到 HTML 文件中可以使用了.采用 touchstart 与 tou ...
- iOS CAReplicatorLayer 实现脉冲动画效果
iOS CAReplicatorLayer 实现脉冲动画效果 效果图 脉冲数量.速度.半径.透明度.渐变颜色.方向等都可以设置.可以用于地图标注(Annotation).按钮长按动画效果(例如录音按钮 ...
- AnimCheckBox按钮点击动画效果《IT蓝豹》
AnimCheckBox按钮点击动画效果 AnimCheckBox按钮点击动画效果,点击选中后勾选框选择效果,很不错的动画功能.项目来源:https://github.com/lguipeng/Ani ...
- 基于jQuery CSS3鼠标点击动画效果
分享基于jQuery CSS3鼠标点击动画效果支持图片或内容滑动,允许设置动画延迟效果.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div class="co ...
- iOS开发 QQ粘性动画效果
QQ(iOS)客户端的粘性动画效果 时间 2016-02-17 16:50:00 博客园精华区 原文 http://www.cnblogs.com/ziyi--caolu/p/5195615.ht ...
- 轻松实现Android,iOS的一个手势动画效果
先来看效果 这是iOS下的效果,android下完全一致.通过do_GestureView组件和do_Animation组件,deviceone能很容易实现复杂的跨平台纯原生动画效果,这个示例就是通过 ...
- iOS开发之吸附动画效果
步骤:1.使用singleviewapplication创建新的项目 2.在.h文件中创建两张图片的实例对象,并与相关的图片进行相连:创建一个UIDynamicAnimator实例对象 3.在.m文件 ...
- ios开发之--简单动画效果的添加
记录一个简单的动画效果,自己写的,很简单,仅做记录. 附一个demo的下载地址: https://github.com/hgl753951/hglTest.git 代码如下: 1,准备 BOOL _i ...
- ios 自定义加载动画效果
在开发过程中,可能会遇到各种不同的场景需要等待加载成功后才能显示数据.以下是自定义的一个动画加载view效果. 在UIViewController的中加载等到效果,如下 - (void)vi ...
随机推荐
- 解析json数组
解析json数组 JSONArray jsonArray = new JSONArray(markingStr); int iSize = jsonArray.length(); for (int i ...
- Android启动脚本init.rc(2)
在Android中使用启动脚本init.rc,可以在系统的初始化中进行简单的操作. init.rc启动脚本路径:system/core/rootdir/init.rc 内容: Commands:命令 ...
- 我想操作的是利用SqlDataAdapter的几个Command属性(InsertCommand,UpdateCommand,DeleteCommand)来更新数据库
我想操作的是利用SqlDataAdapter的几个Command属性(InsertCommand,UpdateCommand,DeleteCommand)来更新数据库代码:SqlConnection ...
- MySql绿色版安装过程记录
作为程序猿,要多动手,周末趁着有空且笔记本刚刚装了系统,所以就配置了下绿色版的MySQL. 多动手,多动手,多动手. 多总结,多总结,多总结. 以下为正文: 一.下载MySQL绿色版: 1.这个地址: ...
- 解决airserver在Windows下安装失败的问题
airserver 可以将iphone 实时投影到mac 和 pc.在mac上安装非常简单.但是在Windows上安装时会有很多问题.之前我电脑安装很快就完成了(因为我之前已经在不知情的前提先事先装过 ...
- [iOS]C语言技术视频-02-程序分支结构(if...else)
下载地址: 链接: http://pan.baidu.com/s/1dREc2 密码: egbt
- Struts2---OGNL表达式和EL表达式
在action里放入actioncontext的变量值 ActionContext.getContext().put("forumList", forumList); 在jsp里如 ...
- asp.net 输出Excel
private void lbtExportToExcel_Click(object sender, EventArgs e) { string strdate = DateTime.Now.Mont ...
- iOS开发——九切片
这个虽然就我来说,感觉它没啥用,但还是放这吧,有时间了把内容补上.
- 超全!整理常用的iOS第三方资源
一:第三方插件 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地址:https://github. ...