在我的代码中,我需要获取触摸之前的坐标来呈现弹出窗口。 这是代码:如何在呈现popover之前获取触摸坐标?
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
方法中的弹出窗口代码。
我不明白 - 您只需将手势添加到视图中,然后显示弹出式视图即可。你为什么认为pop tou会在touchesBegan之前出现? touchesBegan只会在用户触摸self.view时调用...... – 2013-05-01 11:51:32
@AviTsadok我已经意识到touchesBegan从来没有被调用过,但我无法弄清楚我的代码中有什么问题 – aneuryzm 2013-05-01 12:06:52
首先,touchesBegan是一个UIView方法,而不是View Controller方法,这就是为什么它从来没有被调用。其次,如果你添加了轻击手势,为什么你需要覆盖touchesBegan方法(你在错误的地方做过)? – 2013-05-01 12:08:49