【发布时间】:2012-05-09 12:04:56
【问题描述】:
在某个框架内拖动一个 UIView,比如 (0, 0, 320, 190)。如何使用偏移量拖动 UIView。即当我触摸 UIView 时, UIView 不应该在手指下移动。
UIView 应该移动并在上面的框架内移动。我该怎么做?
请告诉我想法?
【问题讨论】:
-
touchesmoved :我覆盖它并将触摸点设置为中心
-
方法 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
-
你能发布你的实现吗?
-
-(void)touchesMoved:(NSSet )touches withEvent:(UIEvent *)event{ UITouch touch = [[event allTouches] anyObject]; CGPoint touchPoint = [touch locationInView:self]; CGFloat xDiff = touchPoint.x - mTouchStartPoint.x; CGFloat yDiff = touchPoint.y - mTouchStartPoint.y; self.center = CGPointMake(self.center.x + xDiff, self.center.y + yDiff); }
-
请更新您的问题并格式化。不要在 cmets 中发布太多代码。
标签: iphone ios5 uiview draggable