UILongPressGestureRecognizer按下坐标

时间:2013-09-01 16:21:13

标签: ios objective-c uiimageview uigesturerecognizer

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

1 个答案:

答案 0 :(得分:3)

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

可能就是你要找的东西。根据{{​​1}}坐标

,这会为您提供触摸点的CGPoint