IPhone UIGestures

I used

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleTap];
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
    UIView* view = gestureRecognizer.view;
    CGPoint loc = [gestureRecognizer locationInView:view];
}

But it gave me an error in CGPoint loc = [gestureRecognizer locationInView:view]; Why ???

+3
source share
2 answers

I do not see an error in your code, but the error indicates that the instance of gestureRecognizer is not being transmitted by UITapGestureRecognizer. Place a breakpoint on the fault line and get the gestureRecognizer type identifier.

In addition: make sure that you are using SDK 4.0 or higher from iPhone. Gesture recognition devices appeared in version 3.2 for the iPad and 4.0 for the iPhone.) I suspect that you are fine, although I think you would get the error earlier if you had not used the correct SDK.

+1
source

try using:

CGPoint loc = [gestureRecognizer locationInView:self.view];

, , UIView * :

UIView* gesturevView = gestureRecognizer.view; 
CGPoint loc = [gestureRecognizer locationInView:gesturevView];
0

Source: https://habr.com/ru/post/1766742/


All Articles