码迷,mamicode.com
首页 > 其他好文 > 详细

UITouch

时间:2017-09-27 21:43:49      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:事件   特殊情况   sel   copyright   count   ast   定义   nbsp   ext   

 1 //
 2 //  ViewController.m
 3 //  UIWindowsApp
 4 //
 5 //  Created by  on 21/09/2017.
 6 //  Copyright ? 2017 . All rights reserved.
 7 //
 8 
 9 #import "ViewController.h"
10 #import "ViewController2.h"
11 
12 @interface ViewController ()
13 
14 @end
15 
16 @implementation ViewController
17 
18 
19 
20 
21 - (void)viewDidLoad {
22     [super viewDidLoad];
23     
24     UIImage* image = [UIImage imageNamed:@"1.jpg"];
25     
26     UIImageView* iView = [[UIImageView alloc]init];
27     
28     iView.image = image;
29     
30     iView.frame = CGRectMake(50, 100, 220, 300);
31     
32     iView.tag = 101;
33     
34     [self.view addSubview:iView];
35 
36     
37 }
38 //手指触碰到屏幕
39 -(void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
40 {
41     UITouch* touch = [touches anyObject];
42     if(touch.tapCount == 1)
43     {
44         NSLog(@"单击"); //
45     }else if(touch.tapCount == 2)
46     {
47         NSLog(@"双击666");//双击时会触发单击事件,什么鬼???
48     }
49     _mPtLast = [touch locationInView:self.view];
50     NSLog(@"手指触碰瞬间");
51 }
52 //手指接触到屏幕,并且没有离开时被调用
53 -(void) touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
54 {
55     UITouch * touch = [touches anyObject];
56     
57     CGPoint pt = [touch locationInView:self.view];
58     
59     float xOffset = pt.x - _mPtLast.x;
60     float yOffset = pt.y - _mPtLast.y;
61     
62     _mPtLast = pt;
63     
64     UIImageView * view  =(UIImageView*)[self.view viewWithTag:101];
65     
66     view.frame = CGRectMake(view.frame.origin.x+xOffset, view.frame.origin.y+yOffset, view.frame.size.width, view.frame.size.height);
67     
68     
69     NSLog(@"x = %f,y=%f",pt.x,pt.y);
70     
71 }
72 //手指离开时被调用
73 -(void) touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
74 {
75     NSLog(@"手指离开时被调用");
76 }
77 
78 // 特殊情况下的中段事件,例如电话,信息切入时,会取消当前的手势。
79 // 用来做紧急的数据保存等
80 -(void) touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
81 {
82     NSLog(@"");
83 }
84 
85 
86 
87 - (void)didReceiveMemoryWarning {
88     [super didReceiveMemoryWarning];
89     // Dispose of any resources that can be recreated.
90 }
91 
92 
93 @end
 1 //
 2 //  ViewController.h
 3 //  UIWindowsApp
 4 //
 5 //  Created by
 6 //  Copyright ?
 7 //
 8 
 9 #import <UIKit/UIKit.h>
10 
11 @interface ViewController : UIViewController
12 {
13    
14     CGPoint _mPtLast;
15     
16     
17 }
18 
19 //属性定义
20 //@property(retain,nonatomic) UITextField* textField;
21 
22 
23 
24 
25 @end 

 

UITouch

标签:事件   特殊情况   sel   copyright   count   ast   定义   nbsp   ext   

原文地址:http://www.cnblogs.com/vector11248/p/7603891.html

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