内部的IOS按钮触摸 - 第一次触摸= Action1和第二次触摸= Action2 //在两者之间循环

时间:2015-08-17 21:40:07

标签: ios swift button action

  

大家好

     

我附上了以下代码。启动后,视图控制器显示   中心有一个标志,底部有四个主要用户按钮。我试着去   如果内部第一个按钮被触及(调用列表),   徽标淡出,中心圆圈显示的名称(列表)   第一个按钮和周围显示按钮与不同的子菜单   点,同时4个主要(初始)按钮褪色并且是   只见最小(低Alpha)。我想实现那个,如果   褪色(半可见)主按钮再次触摸初始视图是   恢复徽标,只有主要的四个菜单按钮。意思,首先   触摸显示子菜单及其动画,第二次单击返回   初步观点。再次单击再次显示子菜单,依此类推。我怎么能够   那样做?

     

感谢Dnai

//
//  ViewController.h
//  NanCom1
//
//  Created by Daniel Habshush on 8/13/15.
//  Copyright © 2015 Daniel Habshush. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@property (nonatomic, retain) IBOutlet UIImageView* logo;

@property (nonatomic, retain) IBOutlet UIButton* button1;
@property (nonatomic, retain) IBOutlet UIButton* button2;
@property (nonatomic, retain) IBOutlet UIButton* button3;
@property (nonatomic, retain) IBOutlet UIButton* button4;


@property (nonatomic, retain) IBOutlet UIButton* listMain;
@property (nonatomic, retain) IBOutlet UIButton* shoppingList;
@property (nonatomic, retain) IBOutlet UIButton* todoList;




@end

//
//  ViewController.m
//  NanCom1
//
//  Created by Daniel Habshush on 8/13/15.
//  Copyright © 2015 Daniel Habshush. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
{
    UIDynamicAnimator* _animator;
    UIGravityBehavior* _gravity;
    UICollisionBehavior* _collision;

}


@synthesize logo, button1, button2, button3, button4, listMain, todoList, shoppingList;



- (void)viewDidLoad {
    [super viewDidLoad];



    logo = [[UIImageView alloc] init];
    UIImage *logoPic = [UIImage imageNamed:@"Logo3.png"];
    logo.image=logoPic;
    logo.frame = CGRectMake(100, 200, 175, 175);
    [logo setAlpha:0];
    [self.view addSubview:logo];


    [UIImageView beginAnimations:nil context:nil];
    [UIImageView setAnimationDuration:3.0];
    [UIImageView setAnimationDelay:0.5];
    [UIImageView setAnimationCurve:UIViewAnimationCurveEaseIn ];

    self.logo.alpha = 1.0;

    [UIImageView commitAnimations];



    button1 = [[UIButton alloc] init];

     [button1 setFrame:CGRectMake(5, 2, 90, 90)];


    [button1 setIsAccessibilityElement:YES];

    button1.backgroundColor = [UIColor clearColor];
    [button1 setBackgroundImage:[UIImage imageNamed:@"Circle.png"] forState:UIControlStateNormal];
    [button1 setTitle:@"Lists" forState:UIControlStateNormal];
    [button1.titleLabel setFont:[UIFont fontWithName:@"Avenir" size:13]];

    [button1 addTarget:self action:@selector(pressed:) forControlEvents:UIControlEventTouchUpInside];


    [button1 setEnabled:YES];


    [self.view addSubview:button1];




    button2 = [[UIButton alloc] init];

    [button2 setFrame:CGRectMake(85, 2, 90, 90)];
    [button2 setIsAccessibilityElement:YES];
    button2.backgroundColor = [UIColor clearColor];
    [button2 setBackgroundImage:[UIImage imageNamed:@"Circle.png"] forState:UIControlStateNormal];
    [button2 setTitle:@"Cirlce" forState:UIControlStateNormal];
    [button2.titleLabel setFont:[UIFont fontWithName:@"Avenir" size:13]];

    [button2 setEnabled:YES];

    [button2 addTarget:self action:@selector(pressed2:) forControlEvents:UIControlEventTouchUpInside];


    [self.view addSubview:button2];





    button3 = [[UIButton alloc] init];

    [button3 setFrame:CGRectMake(160, 2, 90, 90)];

    button3.backgroundColor = [UIColor clearColor];
    [button3 setBackgroundImage:[UIImage imageNamed:@"Circle.png"] forState:UIControlStateNormal];
    [button3 setTitle:@"Location" forState:UIControlStateNormal];
    [button3.titleLabel setFont:[UIFont fontWithName:@"Avenir" size:13]];

    [button3 setEnabled:YES];

     [button2 addTarget:self action:@selector(pressed3:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button3];


    button4 = [[UIButton alloc] init];
    [button4 setFrame:CGRectMake(250, 2, 90, 90)];

    button4.backgroundColor = [UIColor clearColor];
    [button4 setTitle:@"Menu" forState:UIControlStateNormal];
    [button4.titleLabel setFont:[UIFont fontWithName:@"Avenir" size:13]];

    [button4 setBackgroundImage:[UIImage imageNamed:@"Circle.png"] forState:UIControlStateNormal];

    [button4 setEnabled:YES];

     [button2 addTarget:self action:@selector(pressed4:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button4];





    _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
    _gravity = [[UIGravityBehavior alloc] initWithItems:@[button1, button2, button3, button4]];
    [_animator addBehavior:_gravity];


    _collision = [[UICollisionBehavior alloc]
                  initWithItems:@[button1, button2, button3, button4]];

    _collision.translatesReferenceBoundsIntoBoundary = YES;



    [_animator addBehavior:_collision];



    UIDynamicItemBehavior* itemBehaviour4 = [[UIDynamicItemBehavior alloc] initWithItems:@[button4]];
    itemBehaviour4.elasticity = 0.4;
    itemBehaviour4.resistance = 0.65;

    [_animator addBehavior:itemBehaviour4];


    UIDynamicItemBehavior* itemBehaviour3 = [[UIDynamicItemBehavior alloc] initWithItems:@[button3]];
    itemBehaviour3.elasticity = 0.45;
    itemBehaviour3.resistance = 0.5;

    [_animator addBehavior:itemBehaviour3];



    UIDynamicItemBehavior* itemBehaviour2 = [[UIDynamicItemBehavior alloc] initWithItems:@[button2]];
    itemBehaviour2.elasticity = 0.5;
    itemBehaviour2.resistance = 0.3;
    [_animator addBehavior:itemBehaviour2];

    UIDynamicItemBehavior* itemBehaviour1 = [[UIDynamicItemBehavior alloc] initWithItems:@[button1]];
    itemBehaviour1.elasticity = 0.37;
    itemBehaviour1.resistance = 0.2;

    [_animator addBehavior:itemBehaviour1];
}


- (void)pressed:(UIButton*)button1 {

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];

    self.button1.alpha = 0.3;
    self.button2.alpha = 0.3;
    self.button3.alpha = 0.3;
    self.button4.alpha = 0.3;


    [UIView commitAnimations];


    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];

    self.logo.alpha = 0;

    [UIView commitAnimations];


    listMain = [[UIButton alloc] init];

    [listMain setFrame:CGRectMake(100, 200, 175, 175)];

    listMain.backgroundColor = [UIColor clearColor];
    [listMain setBackgroundImage:[UIImage imageNamed:@"Circle.png"] forState:UIControlStateNormal];
    [listMain setTitle:@"Lists" forState:UIControlStateNormal];
    [listMain.titleLabel setFont:[UIFont fontWithName:@"Avenir" size:35]];

    [listMain setAlpha:0];


    [self.view addSubview:listMain];


    todoList = [[UIButton alloc] init];

    [todoList setFrame:CGRectMake(60, 145, 75, 75)];

    todoList.backgroundColor = [UIColor clearColor];
    [todoList setBackgroundImage:[UIImage imageNamed:@"Circle.png"] forState:UIControlStateNormal];
    [todoList setTitle:@"ToDo" forState:UIControlStateNormal];
    [todoList.titleLabel setFont:[UIFont fontWithName:@"Avenir" size:13]];

    [todoList setAlpha:0];


    [self.view addSubview:todoList];


    shoppingList = [[UIButton alloc] init];

    [shoppingList setFrame:CGRectMake(10, 245, 75, 75)];

    shoppingList.backgroundColor = [UIColor clearColor];
    [shoppingList setBackgroundImage:[UIImage imageNamed:@"Circle.png"] forState:UIControlStateNormal];
    [shoppingList setTitle:@"Shopping" forState:UIControlStateNormal];
    [shoppingList.titleLabel setFont:[UIFont fontWithName:@"Avenir" size:13]];

    [shoppingList setAlpha:0];


    [self.view addSubview:shoppingList];

    [UIView commitAnimations];


    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];

    self.listMain.alpha = 1;
    self.todoList.alpha = 1;
    self.shoppingList.alpha = 1;


    [UIView commitAnimations];


}


- (void)pressed2:(UIButton*)button2  {

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];

    self.button2.alpha = 1;
    self.button1.alpha = 1;
    self.button3.alpha = 1;
    self.button4.alpha = 1;

    self.listMain.alpha = 0;
    self.todoList.alpha = 0;
    self.shoppingList.alpha = 0;



    [UIView commitAnimations];
}

- (void)pressed3:(UIButton*)button3  {


    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];

    self.listMain.alpha = 0;
    self.todoList.alpha = 0;
    self.shoppingList.alpha = 0;
    self.logo.alpha = 1;


    [UIView commitAnimations];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];

    self.button2.alpha = 1;
    self.button1.alpha = 1;
    self.button3.alpha = 1;
    self.button4.alpha = 1;


    [UIView commitAnimations];



}

- (void)pressed4:(UIButton*)button4  {

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];

    self.button2.alpha = 1;

    [UIView commitAnimations];


    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];

    self.button1.alpha = 1;

    [UIView commitAnimations];


    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];

    self.button3.alpha = 1;

    [UIView commitAnimations];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];

    self.button4.alpha = 1;

    [UIView commitAnimations];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

0 个答案:

没有答案