模仿汽车大全的点击一个按钮,会弹出多个按钮,同时,点击背景图,多个按钮动画返回的效果

刚开始运行的时候的效果图:

点击ican图标后的效果图:

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

- (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(@"--跳转到第四个图标的页面---");

        }];

    }
}
时间: 2024-08-02 14:57:01

模仿汽车大全的点击一个按钮,会弹出多个按钮,同时,点击背景图,多个按钮动画返回的效果的相关文章

页面table的每行都有一个&lt;input type=&#39;button&#39; /&gt;,如何实现点击按钮在按钮下方弹出一个div,点击空白消失

\ <input id="test" type="button" />/*按钮*/ <div id="tanchu"></div> <script language="javascript"> $(document).ready(function(e) { $("#test").click(function(e) { $("#tanchu"

点击事件中实现弹出一个选择框(如选择网络设置、选择电话短信联系方式)

1.网络设置 public void checkNetwork(){ //获取连接的管理对象 ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); //获取当前正在使用的网络 NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); //判断网络是

C# GridView Edit &amp; Delete, 点击Delete的时候弹出确认框

1. 使用GridView自带属性ShowEditButton和ShowDeleteButton,均设为True  <Columns> ... <asp:CommandField ShowEditButton="True" ShowDeleteButton="True"></asp:CommandField> </Columns> 则在GridView指定列的位置会显示Edit和Delete的LinkButton 2.

IPhone手机页面中点击文本输入框,弹出键盘,网页会放大,如何解决

在head标签中加入以上meta声明.具体属性可以谷歌/百度. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> 我查了下viewport,有几个属性:width - viewport的宽度 height - viewport的高度initial-scale - 初始的缩放比例minim

js的事件冒泡和点击其他区域隐藏弹出层

一.前言 在编写页面的时候,我们经常使用到弹出层.对于弹出层,原本的意义就是增加与用户的交互,提升用户的好感度.如果弹出层都没有较好的体验,那何谈通过交互来提升好感... 首先提出几个弹出层的注意点: 弹出层的界面需要统一,不一致的弹出层并不能增加美感,相反还会显得页面布局更加杂乱无章: 弹出层的设计一定要好看,按钮要符合项目的主色调: 弹出层的宽度固定屏幕占比,设置max-width,高度根据内容自适应: 点击其他区域隐藏弹出层... 二.正文 今天,主要说说点击其他区域隐藏弹出层.笔者被这个

android如何使用DOM来解析XML+如果做一个表情的弹出框

效果图: 如何解析以下的xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <array> <string>(#大笑)</string

bootstrap 弹出框点击其他区域时弹出框不消失选项设置

默认情况下,bootstrap 弹出框点击其他区域时,弹出框会自动关闭,在很多时候,我们可能会希望达到和原生弹出框一样的效果,避免不小心点击其他区域时弹框自动隐藏,尤其是对于一些复杂的表单,重复填写可能会带来很不好的体验效果,所以,我们会希望不会发生这种情况,事实上bootstrap dialog提供了大量的选项可以设置各种dialog的行为和效果.如下所示: <div class="modal fade" id="myModal" tabindex=&quo

代码录播:jQueryMobile 实现一个简单的弹出框效果

今天给大家带来的是 jQueryMobile 实现一个简单的弹出框效果,有兴趣的童鞋可以试试哦~ ^_^ 阅读原文:www.gbtags.com

Android 点击一个按钮,弹出一个对话框

界面非常的简单,就是一个Button,点击这个Button呢,会弹出一个对话框 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout