【代碼筆記】點擊一個按鈕會出現多個按鈕的動畫效果,按鈕動畫

來源:互聯網
上載者:User

【代碼筆記】點擊一個按鈕會出現多個按鈕的動畫效果,按鈕動畫

一,。

二,工程圖。

三,代碼。

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.}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.