我以这种方式在 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 坐标?