我想移動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. 跟蹤MKMapView的中心座標
- 3. 減法通過跟蹤xy座標
- 4. 如何實現NSLog跟蹤CGPoint座標
- 5. 平滑GPS跟蹤路線座標
- 6. 在iPhone上實現跟蹤手勢
- 7. 在iPhone webapp上跟蹤javascript錯誤
- 8. 在iPhone中的Omniture跟蹤
- 9. 攻絲嵌套GridView
- 10. 在QGraphicsItem上跟蹤鼠標位置
- 11. 在網站上跟蹤鼠標點擊
- 12. iPhone GPS座標上傳
- 13. Iphone上的實時人臉跟蹤
- 14. Android系統跟蹤[跟蹤標記]
- 15. 光線跟蹤問題,如何將屏幕座標映射到世界座標?
- 16. 跟蹤畫布x和y座標在mousmove事件上的動畫
- 17. PerformSelector單線程攻絲
- 18. NServicebus - 攻絲ServiceControl MessageFailed事件
- 19. 通過索引攻絲UITableViewHeader
- 20. iPhone - 跟蹤三次接觸
- 21. iPhone跟蹤內存覆蓋
- 22. iPhone視頻跟蹤應用
- 23. Dirty Size,VM跟蹤器,iPhone
- 24. Wordpress光標跟蹤
- 25. 跟蹤鼠標光標android
- 26. 通過txt文件中的座標進行粒子跟蹤
- 27. 跟蹤一個對象的局部座標空間
- 28. 跟蹤當前位置的座標共同
- 29. 跟蹤方面在Linux上
- 30. 跟蹤EXC_BAD_ACCESS在iPad上
[相同](http://www.google.fr/search?aq=f&sourceid=chrome&ie=UTF-8&q=uiimageview+tap) – 2012-03-03 09:30:34