我以这种方式在UIImageView上使用UILongPressGestureRecogniser:

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
    [ImageViewPhotoCard addGestureRecognizer:longPress];


- (void)longPress:(UILongPressGestureRecognizer*)gesture {
if ( gesture.state == UIGestureRecognizerStateEnded ) {

    //NSString *key = [array objectAtIndex:i];

    UIButton* ButtonNote = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    ButtonNote.frame = CGRectMake(100, 200, 80, 80); // position in the parent view and set the size of the button

    [ButtonNote addTarget:self action:@selector(OpenNote:) forControlEvents:UIControlEventTouchUpInside];
    ButtonNote.backgroundColor = [UIColor clearColor];

    UIImage* btnImage = [UIImage imageNamed:@"purple_circle.png"];
    [ButtonNote setBackgroundImage:btnImage forState:UIControlStateNormal];

    [self.ViewA addSubview:ButtonNote];

    [ArrayNotes addObject:ButtonNote];

    [ButtonNote setTitle:@"" forState:UIControlStateNormal];
    [ButtonNote setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
}

如何获得用户按下的点的x和y坐标?

最佳答案

CGPoint location = [gesture locationInView:self.view];
可能就是您想要的。根据self.view坐标,这为您提供了触摸点的CGPoint

关于ios - UILongPressGestureRecognizer打印机坐标,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18560395/

10-10 20:48