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

【iOS开发-触摸】移动的UIView例子

时间:2015-05-18 23:13:43      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:

iOS触摸

方法:

//开始接触
- (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;

实现UIView的移动

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

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];//得到触摸对象
    CGPoint current = [touch locationInView:self];//得到当前触摸所在的点
    CGPoint previous = [touch previousLocationInView:self];//得到触摸所在的上一个点

    CGPoint center = self.center;//拿到UIView的中点
    center.x += current.x - previous.x;
    center.y += current.y - previous.y;
    self.center = center;
}

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

}

【iOS开发-触摸】移动的UIView例子

标签:

原文地址:http://blog.csdn.net/ttf1993/article/details/45824647

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