码迷,mamicode.com
首页 > 移动开发 > 详细

iOS UI-手势(Gesture)

时间:2015-12-30 21:52:33      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

 1 #import "ViewController.h"
 2 
 3 @interface ViewController ()<UIActionSheetDelegate>
 4 @property (strong, nonatomic) UITextField *me_textfield;
 5 
 6 @end
 7 
 8 @implementation ViewController
 9 
10 - (void)viewDidLoad {
11     [super viewDidLoad];
12     [self.view setBackgroundColor:[UIColor lightGrayColor]];
13     /*
14      手势分类:
15      滑动手势、点击手势、双击手势、长按手势等7种
16      */
17     
18 //    self.me_textfield = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 375, 100)];
19 //    self.me_textfield.placeholder = @"请输入";
20 //    self.me_textfield.borderStyle = UITextBorderStyleRoundedRect;
21 //    //self.me_textfield.center =self.view.center;
22 //    [self.view addSubview:self.me_textfield];
23     
24     //创建点击手势
25     UITapGestureRecognizer *click = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickToDoSomething)];
26     [self.view addGestureRecognizer:click];
27     
28     //创建长按手势
29     UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDoSomething)];
30     longPress.minimumPressDuration = 2.0;
31     [self.view addGestureRecognizer:longPress];
32     
33     //创建捏合手势
34     UIPinchGestureRecognizer *pich = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pichToDoSomething)];
35     [self.view addGestureRecognizer:pich];
36     
37     //创建旋转手势
38     UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationToDoSomething)];
39     [self.view addGestureRecognizer:rotation];
40     
41     //创建轻扫手势
42     UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToDoSomething)];
43     [self.view addGestureRecognizer:swipe];
44     
45     //创建拖动手势
46     UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panToDoSomething)];
47     [self.view addGestureRecognizer:pan];
48     
49     //创建屏幕边缘拖动手势
50     UIScreenEdgePanGestureRecognizer *screenEdgePan =[[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(screenEdgePanToDoSomething)];
51     [self.view addGestureRecognizer:screenEdgePan];
52 }
53 #pragma mark - 屏幕边缘拖动手势关联方法
54 - (void)screenEdgePanToDoSomething
55 {
56     NSLog(@"屏幕边缘拖动");
57 }
58 #pragma mark - 拖动手势关联方法
59 - (void)panToDoSomething
60 {
61     NSLog(@"拖动");
62 }
63 #pragma mark - 轻扫手势关联方法
64 - (void)swipeToDoSomething
65 {
66     NSLog(@"轻扫");
67 }
68 #pragma mark - 旋转手势关联方法
69 - (void)rotationToDoSomething
70 {
71     NSLog(@"旋转");
72 }
73 #pragma mark - 捏合手势关联方法
74 - (void)pichToDoSomething
75 {
76     NSLog(@"捏合");
77 }
78 #pragma mark - 长按手势关联方法
79 - (void)longPressToDoSomething
80 {
81     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"关机" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
82     [alert show];
83 }
84 #pragma mark - 点击手势关联方法
85 - (void)clickToDoSomething
86 {
87     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"你点我试试" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
88     [alert show];
89 
90     
91 }
92 
93 
94 - (void)didReceiveMemoryWarning {
95     [super didReceiveMemoryWarning];
96     // Dispose of any resources that can be recreated.
97 }
98 
99 @end

 

iOS UI-手势(Gesture)

标签:

原文地址:http://www.cnblogs.com/oc-bowen/p/5089884.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!