我想移动UIImageView通过tappig屏幕上的位置。我如何获得攻牙手指的X,Y坐标?在iPhone上跟踪攻丝坐标
在viewDidLoad.m
0
A
回答
0
,这可能做的工作:
/* 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方法。
0
您可以使用以下任何方法
如果你希望它是在移动感动开始活动,如果你希望它是在结束事件的触摸移动使用
- (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
它很简单,为什么你不搜索谷歌或stackoverflow? – HarshIT 2012-03-03 09:43:21
相关问题
- 1. 如何跟踪mapkit上的坐标
- 2. IPhone分段控制攻丝
- 3. 在iphone上跟踪Facebook Apprequests
- 4. 持续跟踪鼠标坐标
- 5. 跟踪Qt中的鼠标坐标
- 6. 在twitter上跟踪标签
- 7. 跟踪MKMapView的中心坐标
- 8. 减法通过跟踪xy坐标
- 9. 平滑GPS跟踪路线坐标
- 10. 算法从KML跟踪GPS坐标
- 11. 如何实现NSLog跟踪CGPoint坐标
- 12. 被点击的Sprite的跟踪坐标
- 13. 在iPhone上跟踪横向移动
- 14. 在iPhone上跟踪多个触摸
- 15. 在iPhone webapp上跟踪javascript错误
- 16. 在iPhone上实现跟踪手势
- 17. 如何在攻丝物体上执行动作而不是释放攻丝?
- 18. 在iPhone中的Omniture跟踪
- 19. 攻丝嵌套GridView
- 20. Iphone上的实时人脸跟踪
- 21. iPhone上的3D头部跟踪
- 22. iPhone GPS坐标上传
- 23. 在Java上跟踪鼠标位置WorldWind
- 24. 在QGraphicsItem上跟踪鼠标位置
- 25. 在网站上跟踪鼠标点击
- 26. 跟踪粉丝页面上的Facebook Like转换页面
- 27. Android系统跟踪[跟踪标记]
- 28. 在Swift动画播放期间跟踪对象的坐标WithDuration
- 29. 在平移时跟踪MKMapView中心坐标
- 30. 光线跟踪问题,如何将屏幕坐标映射到世界坐标?
[相同](http://www.google.fr/search?aq=f&sourceid=chrome&ie=UTF-8&q=uiimageview+tap) – 2012-03-03 09:30:34