在我的代码中,我需要在呈现弹出框之前获取触摸的坐标。这是代码:
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setDelegate:self];
[self.view addGestureRecognizer:tapRecognizer];
FreeAndNil(tapRecognizer);
ratingSliderViewController = [[CMRatingSliderViewController alloc] init];
ratingPopoverController = [[UIPopoverController alloc] initWithContentViewController:ratingSliderViewController];
[ratingPopoverController setDelegate:self];
[ratingPopoverController setPopoverContentSize:CGSizeMake(360.0, 50.0)];
[self setPopoverController:ratingPopoverController];
[ratingPopoverController presentPopoverFromRect:CGRectMake(latestTouchPoint.x, latestTouchPoint.y, 10.0,10.0) inView:detailView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.view removeGestureRecognizer:tapRecognizer];
...
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
latestTouchPoint = [touch locationInView:self.view];
}
然而,弹出框是在touchesBegan
调用之前呈现的。我该如何解决这个问题?我宁愿不使用延迟或在通用touchesBegan
方法中运行弹出代码。