在iPhone上跟踪攻丝坐标
答
,这可能做的工作:
/* Create the Tap Gesture Recognizer */
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTaps:)];
/* The number of fingers that must be on the screen */
self.tapGestureRecognizer.numberOfTouchesRequired = 1;
/* The total number of taps to be performed before the gesture is recognized */
self.tapGestureRecognizer.numberOfTapsRequired = 1;
/* Add this gesture recognizer to our view */
[self.view addGestureRecognizer:self.tapGestureRecognizer];
然后在handleTaps:方法
- (void) handleTaps:(UITapGestureRecognizer*)paramSender{
NSUInteger touchCounter = 0;
for (touchCounter = 0; touchCounter < paramSender.numberOfTouchesRequired; touchCounter++)
{
CGPoint touchPoint = [paramSender locationOfTouch:touchCounter inView:paramSender.view];
NSLog(@"Touch #%lu: %@", (unsigned long)touchCounter+1, NSStringFromCGPoint(touchPoint));
}
}
当然,要实现对您的需求handleTaps方法。
答
您可以使用以下任何方法
如果你希望它是在移动感动开始活动,如果你希望它是在结束事件的触摸移动使用
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{}
,使用此
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{}
并放置粘贴下面
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint pt = [[touches anyObject] locationInView:self.view];
imageView.center = CGPointMake(pt.x,pt.y);
}
的代码
在上面的代码中,pt包含触摸位置的x和y坐标。 此外,您也可以使用动画来平滑移动。
+0
它很简单,为什么你不搜索谷歌或*? – HarshIT 2012-03-03 09:43:21
[相同](http://www.google.fr/search?aq=f&sourceid=chrome&ie=UTF-8&q=uiimageview+tap) – 2012-03-03 09:30:34