2

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

4

1 回答 1

3

CGPoint location = [gesture locationInView:self.view];

可能是您正在寻找的。根据self.view坐标,这将为您提供触摸点的 CGPoint

于 2013-09-01T16:23:59.727 回答