ios按钮长按事件
来源:互联网 发布:明星淘宝店哪里找 编辑:程序博客网 时间:2024/05/16 12:01
//
// ViewController.m
// 按钮长按事件
//
// Created by soft-angel on 16/3/30.
// Copyright © 2016年 soft-angel. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
{
UIButton * _btn1;
UIButton * _btn2;
UIButton * _btn3;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_btn1 = [[UIButtonalloc]initWithFrame:CGRectMake(120, 260, 80, 80)];
[_btn1addTarget:selfaction:@selector(btn1:)forControlEvents:UIControlEventTouchUpInside];
[_btn1setBackgroundImage:[UIImageimageNamed:@"2.png"]forState:UIControlStateNormal];
UILongPressGestureRecognizer * longGesture = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(longGesture:)];
longGesture.minimumPressDuration = 0.5f;
[_btn1addGestureRecognizer:longGesture];
_btn2 = [[UIButtonalloc]initWithFrame:CGRectMake(120, 260, 80, 80)];
[_btn2addTarget:self action:@selector(btn2:) forControlEvents:UIControlEventTouchUpInside];
[_btn2setBackgroundImage:[UIImageimageNamed:@"1.png"] forState:UIControlStateNormal];
[self.viewaddSubview:_btn2];
_btn3 = [[UIButtonalloc]initWithFrame:CGRectMake(120, 260, 80, 80)];
[_btn3addTarget:self action:@selector(btn3:) forControlEvents:UIControlEventTouchUpInside];
[_btn3setBackgroundImage:[UIImageimageNamed:@"3.png"] forState:UIControlStateNormal];
[self.viewaddSubview:_btn3];
[self.view addSubview:_btn1];
}
-(void)show
{
[UIViewbeginAnimations:nil context:nil];
[UIViewsetAnimationDuration:0.5f];
[UIViewsetAnimationCurve:7];
_btn2.frame =CGRectMake(80, 150, 80, 80);
_btn3.frame =CGRectMake(180, 150, 80, 80);
[UIViewcommitAnimations];
}
-(void)hidden
{
[UIViewanimateWithDuration:0.5f animations:^{
_btn2.frame =_btn1.frame;
_btn3.frame =_btn1.frame;
} completion:nil];
}
-(void)btn1:(UIButton *)sender
{
NSLog(@"111");
}
-(void)btn2:(UIButton *)sender
{
NSLog(@"222");
[selfhidden];
}
-(void)btn3:(UIButton *)sender
{
NSLog(@"333");
[selfhidden];
}
-(void)longGesture:(UILongPressGestureRecognizer *)gesture
{
if (gesture.state ==UIGestureRecognizerStateBegan)
{
[selfshow];
}
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[selfhidden];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- ios按钮长按事件
- cocos2dx 按钮长按事件
- ios长按事件
- [Cocos2d-js]长按按钮事件
- Unity3D UGUI按钮长按事件
- iOS 长按事件 UILongPressGestureRecognizer
- ios button长按事件
- IOS 长按手势事件
- 【iOS】自定义控件之长按按钮
- Extjs鼠标长按事件(实现长按按钮触发事件的方法:mousedown、mouseup)
- ios-添加长按事件
- IOS长按事件的方法
- IOS UIbutton的长按事件实现
- IOS长按事件--UILongPressGestureRecognizer
- iOS 长按事件的解决方法
- ios 触发UIButton长按事件
- IOS长按事件的方法
- Android 按钮的长按 和点击事件
- c++第四次上机
- Delphi 调用C#编写的WebService 参数为Null解决方法
- LeetCode *** 134. Gas Station
- C++组合与继承
- UVA 140 Bandwidth
- ios按钮长按事件
- 爬虫链接
- 21. Merge Two Sorted Lists
- git初建立服务器的几个问题
- elf格式分析
- php trait特性
- C++常用库的函数详解
- 错误记录
- C++设计模式之单例模式