#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,strong) UIButton *gesturesBtn;
@end
@implementation ViewController
@synthesize gesturesBtn=_gesturesBtn;
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
self.navigationItem.title=@"手势测试";
_gesturesBtn=[[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width*0.35, self.view.frame.size.height*0.4, self.view.frame.size.width*0.3, self.view.frame.size.height*0.1)];
[_gesturesBtn setBackgroundColor:[UIColor blueColor]];
[_gesturesBtn.layer setCornerRadius:5.0];
[_gesturesBtn.layer setBorderWidth:0.5];
[_gesturesBtn setTitle:@"GesturesTest" forState:UIControlStateNormal];
[_gesturesBtn setTintColor:[UIColor blackColor]];
//慢速滑动
UIPanGestureRecognizer *panLeft=[[UIPanGestureRecognizeralloc]initWithTarget:self action:@selector(panLeftAction:)];
[self.view addGestureRecognizer:panLeft];
//单击手势
UITapGestureRecognizer *tapGes=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//点按次数
[tapGes setNumberOfTapsRequired:1];
//点按手指数量
[tapGes setNumberOfTouchesRequired:1];
//把手势加到该按钮视图上
[_gesturesBtn addGestureRecognizer:tapGes];
[self.view addSubview:_gesturesBtn];
}
//慢速滑动手势响应事件
-(void)panLeftAction:(UISwipeGestureRecognizer *)sender{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"慢滑动"delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
//点按手势响应事件
-(void)tapAction:(UITapGestureRecognizer *)sender{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"点按手势" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
@end