How do I get the coordinates for finger tapping in UIView?

前端 未结 5 735
-上瘾入骨i
-上瘾入骨i 2020-12-19 05:31

How do I get the coordinates for finger tapping in UIView? (I would prefer not to use a big array of buttons)

Thank you

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 05:50

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        CGPoint touchPoint = [touch locationInView:myView];
        NSLog("%lf %lf", touchPoint.x, touchPoint.y);
    }
    

    You need to do something like this. touchesBegan:withEvent: is a method of UIResponder from which UIView and UIViewController both are derived. If you google for this method then you will find several tutorials. MoveMe sample from Apple is a good one.

提交回复
热议问题