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

Touch

时间:2016-01-13 21:38:17      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

前面写了几次提到UITouch,也提到了UITouch的三个代理方法

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

这里还有几个代理方法

 

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;//触摸取消事件

 

- (void)remoteControlReceivedWithEvent:(UIEvent *)event;//注册接受触摸事件的Control

下面写了一个简单的DEMO,触摸时,移动图片

 

- (void)loadView {

[super loadView];

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(20.050.045.045.0)];

image.image = [UIImage imageNamed:@"1.png"];

image.tag = 100;

[self.view addSubview:image];

 

}

 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

UITouch *touch = [touches anyObject];

UIImageView *view1 = (UIImageView*)[self.view  viewWithTag:100];

CGPoint point = [touch  locationInView:self.view];

CGRect  frame = view1.frame;

frame.origin = point;

view1.frame = frame;

}

Touch

标签:

原文地址:http://www.cnblogs.com/zhao-jie-li/p/5128477.html

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