0
我怎樣才能使用UITapGestureRecognizer
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
}
方法考慮的位置?
我怎樣才能使用UITapGestureRecognizer
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
}
方法考慮的位置?
手勢識別器具有locationInView:view方法。 也UIGestureRecognizer有.view屬性,所以你可以使用它。
這裏是一個例子。
-(void)handleGesture:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint p = [gestureRecognizer locationInView:self.navigationController.toolbar];
CGRect nextButtonRect = CGRectMake(self.navigationController.toolbar.frame.size.width * 2/3,
0,
self.navigationController.toolbar.frame.size.width/3,
self.navigationController.toolbar.frame.size.height);
CGRect previousButtonRect = CGRectMake(0,
0,
self.navigationController.toolbar.frame.size.width/3,
self.navigationController.toolbar.frame.size.height);
if (CGRectContainsPoint(previousButtonRect, p))
[self tapOnPreviousNews];
if (CGRectContainsPoint(nextButtonRect, p))
[self tapOnNextNews];
}