【代码笔记】iOS-点击一个按钮会出现多个按钮的动画效果
一,效果图。

二,工程图。

三,代码。
RootViewController.h

#import <UIKit/UIKit.h> @interface RootViewController : UIViewController
{
UIImageView *iCanImageView;
UIImageView *menu_carImageView;
UIImageView *menu_movieImageView;
UIImageView *menu_setImageView;
UIImageView *menu_photoImageView;
BOOL isRonating;
int count;
}
@end

RootViewController.m

#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. //初始化背景图
[self initBackgroundView]; }
#pragma -mark -functions
-(void)initBackgroundView
{
//隐藏导航条
self.navigationController.navigationBarHidden=YES; //设置背景图片
UIImageView *bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"main_bg.png"]];
bgImage.frame = self.view.bounds; //背景图添加手势
UITapGestureRecognizer *bgTgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgClick)];
[bgImage addGestureRecognizer:bgTgr];
bgImage.userInteractionEnabled = YES; [self.view addSubview:bgImage]; //背景图上的小图标
iCanImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ican.png"]];
iCanImageView.center = CGPointMake(50, 400); //小图标添加手势
UITapGestureRecognizer *iCanTgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(iCanClick)];
[iCanImageView addGestureRecognizer:iCanTgr];
iCanImageView.userInteractionEnabled = YES; //弹出的4个设置的小图标
//车图标
menu_carImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menu_car.png"]];
menu_carImageView.tag = 3;
menu_carImageView.center = iCanImageView.center; //视频的图标
menu_movieImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menu_movie.png"]];
menu_movieImageView.tag = 4;
menu_movieImageView.center = iCanImageView.center; //图片的图标
menu_photoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
menu_photoImageView.tag = 5;
menu_photoImageView.center = iCanImageView.center; //设置的图标
menu_setImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menu_set.png"]];
menu_setImageView.tag = 6;
menu_setImageView.center = iCanImageView.center; [self.view addSubview:menu_carImageView];
[self.view addSubview:menu_movieImageView];
[self.view addSubview:menu_photoImageView];
[self.view addSubview:menu_setImageView];
[self.view addSubview:iCanImageView]; // 将小图片都添加到数组,最后循环数组为每一个小图片添加点击手势
NSArray *imageViewArr = [[NSArray alloc] initWithObjects:menu_carImageView,menu_movieImageView,menu_photoImageView,menu_setImageView, nil]; for(UIImageView *view in imageViewArr)
{
UITapGestureRecognizer *jumpTo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Jump:)];
view.userInteractionEnabled = YES;
[view addGestureRecognizer:jumpTo];
} // 判断图标是否旋转,还有小图标是否飞出
isRonating = NO; // 用于计数小图片旋转的时间
count = 0;
}
#pragma -mark -doClickActions
//点击iCan图标,弹出图标
-(void)iCanClick
{
CGAffineTransform trans = iCanImageView.transform;
if(isRonating == NO)
{
CGAffineTransform newTrans = CGAffineTransformRotate(trans, -2*M_1_PI);
[UIView animateWithDuration:0.3 animations:^{
iCanImageView.transform = newTrans;
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(GoOut:) userInfo:nil repeats:YES];
}];
isRonating = YES;
}
else
{
CGAffineTransform newTrans = CGAffineTransformRotate(trans, 2*M_1_PI);
[UIView animateWithDuration:0.3 animations:^{
iCanImageView.transform = newTrans;
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(Back:) userInfo:nil repeats:YES];
}];
isRonating = NO;
}
}
//点击背景图,图标旋转回原位
-(void)bgClick
{
if(isRonating == YES)
{
CGAffineTransform trans = iCanImageView.transform;
CGAffineTransform newTrans = CGAffineTransformRotate(trans, 2*M_1_PI);
[UIView animateWithDuration:0.3 animations:^{
iCanImageView.transform = newTrans;
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(Back:) userInfo:nil repeats:YES];
}];
isRonating = NO;
}
}
//弹出的动作
-(void)GoOut:(id)sender
{
NSTimer *tiemr = (NSTimer *)sender;
count++;
[UIView animateWithDuration:0.2 animations:^{
menu_carImageView.center = [self location:CGPointMake(-10, 128)];
}];
if(count>2)
[UIView animateWithDuration:0.2 animations:^{
menu_movieImageView.center = [self location:CGPointMake(45, 100)];
}];
if(count>3)
[UIView animateWithDuration:0.2 animations:^{
menu_photoImageView.center = [self location:CGPointMake(88, 55)];
}];
if(count>4)
[UIView animateWithDuration:0.2 animations:^{
menu_setImageView.center = [self location:CGPointMake(105, -8)];
}];
if(count>5)
{
count = 0;
[tiemr invalidate];
}
}
//回归原位的动作
-(void)Back:(id)sender;
{
NSTimer *timer = (NSTimer *)sender;
count ++;
[UIView animateWithDuration:0.2 animations:^{
[self Ronate:menu_setImageView];
}];
if(count>3)
[UIView animateWithDuration:0.2 animations:^{
[self Ronate:menu_photoImageView];
}];
if(count>6)
[UIView animateWithDuration:0.2 animations:^{
menu_setImageView.center = iCanImageView.center;
}];
if(count>8)
[UIView animateWithDuration:0.2 animations:^{
menu_photoImageView.center = iCanImageView.center;
}];
if(count>5)
[UIView animateWithDuration:0.2 animations:^{
[self Ronate:menu_movieImageView];
}];
if(count>9)
[UIView animateWithDuration:0.2 animations:^{
menu_movieImageView.center = iCanImageView.center;
}];
if(count >7)
[UIView animateWithDuration:0.2 animations:^{
[self Ronate:menu_carImageView];
}];
if(count>10)
[UIView animateWithDuration:0.2 animations:^{
menu_carImageView.center = iCanImageView.center;
}];
if(count>11)
{
menu_carImageView.transform = CGAffineTransformMakeRotation(0);
menu_movieImageView.transform = CGAffineTransformMakeRotation(0);
menu_photoImageView.transform = CGAffineTransformMakeRotation(0);
menu_setImageView.transform = CGAffineTransformMakeRotation(0);
count = 0;
[timer invalidate];
}
}
-(CGPoint)location:(CGPoint)p
{
CGFloat x = CGRectGetMaxX(iCanImageView.frame);
CGFloat y = iCanImageView.center.y;
CGPoint pp = CGPointMake(x+p.x+20, y-p.y-10);
return pp;
}
-(void)Ronate:(UIImageView *)view
{
view.transform = CGAffineTransformMakeRotation(360.0f*count);
}
// 界面跳转
-(void)Jump:(id)sender
{
UIGestureRecognizer *t = (UIGestureRecognizer *)sender;
UIImageView *view = (UIImageView *)t.view;
UIEdgeInsets set;
set.top = 5.0f;
set.bottom = 5.0f;
set.left = 5.0f;
set.right = 5.0f;
if(view.tag == 3)
{
[self Scale:view];
}
else if(view.tag == 4)
{
[self Scale:view];
}
else if(view.tag == 5)
{
[self Scale:view];
}
else
{
[self Scale:view];
}
} // 放大和缩小图片
-(void)Scale:(UIImageView *)view
{
if(view.tag == 3)
{
CGFloat scale = 1.5;
CGAffineTransform trans = view.transform;
[UIImageView animateWithDuration:0.5 animations:^{
CGAffineTransform newTrans = CGAffineTransformScale(trans, scale, scale);
CGAffineTransform newTrans1 = CGAffineTransformScale(trans, 0.5, 0.5);
view.transform = newTrans;
menu_movieImageView.transform = newTrans1;
menu_photoImageView.transform = newTrans1;
menu_setImageView.transform = newTrans1;
view.alpha = 0.1;
menu_movieImageView.alpha = 0.1;
menu_photoImageView.alpha = 0.1;
menu_setImageView.alpha = 0.1;
} completion:^(BOOL finished) {
NSLog(@"--跳转到第一个图标的页面---");
}];
}
else if(view.tag == 4)
{
CGFloat scale = 1.5;
CGAffineTransform trans = view.transform;
[UIImageView animateWithDuration:0.5 animations:^{
CGAffineTransform newTrans = CGAffineTransformScale(trans, scale, scale);
CGAffineTransform newTrans1 = CGAffineTransformScale(trans, 0.5, 0.5);
view.transform = newTrans;
menu_carImageView.transform = newTrans1;
menu_photoImageView.transform = newTrans1;
menu_setImageView.transform = newTrans1;
view.alpha = 0.1;
menu_carImageView.alpha = 0.1;
menu_photoImageView.alpha = 0.1;
menu_setImageView.alpha = 0.1;
} completion:^(BOOL finished) {
NSLog(@"--跳转到第二个图标的页面---"); }];
}
else if(view.tag == 5)
{
CGFloat scale = 1.5;
CGAffineTransform trans = view.transform;
[UIImageView animateWithDuration:0.5 animations:^{
CGAffineTransform newTrans = CGAffineTransformScale(trans, scale, scale);
CGAffineTransform newTrans1 = CGAffineTransformScale(trans, 0.5, 0.5);
view.transform = newTrans;
menu_movieImageView.transform = newTrans1;
menu_carImageView.transform = newTrans1;
menu_setImageView.transform = newTrans1;
view.alpha = 0.1;
menu_movieImageView.alpha = 0.1;
menu_carImageView.alpha = 0.1;
menu_setImageView.alpha = 0.1;
} completion:^(BOOL finished) {
NSLog(@"--跳转到第三个图标的页面---"); }];
}
else
{
CGFloat scale = 1.5;
CGAffineTransform trans = view.transform;
[UIImageView animateWithDuration:0.5 animations:^{
CGAffineTransform newTrans = CGAffineTransformScale(trans, scale, scale);
CGAffineTransform newTrans1 = CGAffineTransformScale(trans, 0.5, 0.5);
view.transform = newTrans;
menu_movieImageView.transform = newTrans1;
menu_photoImageView.transform = newTrans1;
menu_carImageView.transform = newTrans1;
view.alpha = 0.1;
menu_movieImageView.alpha = 0.1;
menu_photoImageView.alpha = 0.1;
menu_carImageView.alpha = 0.1;
} completion:^(BOOL finished) {
NSLog(@"--跳转到第四个图标的页面---"); }]; }
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

【代码笔记】iOS-点击一个按钮会出现多个按钮的动画效果的更多相关文章
- 【代码笔记】iOS-点击一个button,出6个button
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> //加入头文件 #import "DCPathB ...
- 【代码笔记】iOS-点击cell时候的动画翻转
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- web前端学习(三)css学习笔记部分(8)-- SVN的介绍和应用、CSS动画效果、CSS3布局属性全接触
15.SVN的介绍和应用 15.1.SVN的介绍和应用课程概要 将代码进行集中管理,有版本号的进行迭代,方便集体工作的build流程 15.2.SVN的介绍 SVN是Subversion的简称,是一个 ...
- 完整版百度地图点击列表定位到对应位置并有交互动画效果demo
1.前言 将地图嵌入到项目中的需求很多,好吧,我一般都是用的百度地图.那么今天就主要写一个完整的demo.展示一个列表,点击列表的任一内容,在地图上定位到该位置,并有动画效果.来来来,直接上demo ...
- 【代码笔记】iOS-点击搜索按钮,或放大镜后都会弹出搜索框
一, 效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> #import "CLHSearchBar.h ...
- 【代码笔记】iOS-点击顶点处,弹出另一个小的界面
一,效果图. 二,文件目录. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewControlle ...
- 【代码笔记】iOS-点击搜索跳转到另外一个页面
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- 【代码笔记】iOS-点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多。
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- 【代码笔记】iOS-点击加号增加书架,点击减号减少书架
一,效果图. 二,工程图. 三,代码. ReaderViewController.h #import <UIKit/UIKit.h> @interface ReaderViewContro ...
随机推荐
- 使用Spark分析拉勾网招聘信息(三): BMR 入门
简述 本文,意在以最小的篇幅,来帮助对大数据和Spark感兴趣的小伙伴,能尽快搭建一个可用的Spark开发环境.力求言简意赅.文章,不敢自称BMR的最佳实践,但绝对可以帮助初学者,迅速入门,能够专心于 ...
- Swift 2.2发布
Swift 2.2 发布了.支持linux平台.Swift是一种使用现代的安全设计方式和软件设计模式构建的通用编程语言.该版本语言更新如下: SE-0001: Allow (most) keyword ...
- zTree的使用2
前台代码: @using Models; @{ Layout = "~/Views/Shared/_Layout.cshtml"; } <link type="te ...
- Oracle数据库,join多表关联方式、union结果集合并
join on : 多表关联 内连接 :与其他表连接 from 表1 t join 表2 s on t.字段1 =s.字段2 join 表3 n on n.字段3=t.字段1 或 from 表1 ...
- IT职业思考 谈谈IT外包公司
个人能力强才是王道 1. 为什么像BAT.HP.IBM.华为这些大公司还需要外包,他们已经有那么多的技术人员 一个公司,如果没有那么多项目,光养这些技术人员,实际的经营成本确实不低,但是这些技术人员又 ...
- 市面上常见的javaEE WEB服务软件
常见的市面上web服务软件 Tomcat:轻量级的WEB应用程序服务器(开源),开源组织Apache的产品.免费的.支持部分的JavaEE规范.(servlet.jsp.jdbc,但ejb, rmi不 ...
- Jquery实际应用,判断radio,selelct,checkbox是否选中及选中的值
jquery取radio单选按钮的值 $("input[name='items']:checked").val(); 另:判断radio是否选中并取得选中的值 如下所示: fun ...
- 通过angularjs的directive以及service来实现的列表页加载排序分页
前两篇:(列表页的动态条件搜索,我是如何做列表页的)分别介绍了我们是如何做后端业务系统数据展示类的列表页以及动态搜索的,那么还剩下最重要的一项:数据展示.数据展示一般包含三部分: 数据列头 数据行 分 ...
- Java中的GOF23(23中设计模式)--------- 单例模式(Singleton)
Java中的GOF23(23中设计模式)--------- 单例模式(Singleton) 在Java这这门语言里面,它的优点在于它本身的可移植性上面,而要做到可移植的话,本身就需要一个中介作为翻译工 ...
- ENVI【非监督分类】
非监督分类的概念: 非监督分类,又称“聚类分析或者点群分析”.在多光谱图像中搜寻.定义其自然相似光谱集群的过程.它不必对图像地物获取先验知识,仅依靠图像上不同地物光谱信息进行特征提取,在统计特征的差别 ...