检查是否-touchesEnded:触及withEvent:event在某个rect内

时间:2015-11-22 19:46:57

标签: ios objective-c

如果在矩形区域内(touchUpInside)手指被抬起,我想触发一个segue。不知道怎么做。任何帮助都会有很大的帮助。

1 个答案:

答案 0 :(得分:1)

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  CGRect targetRect = CGRectZero; // replace this with the rect the user has to touch to trigger the segue

  UITouch *touch = [touches anyObject];
  CGPoint touchLocation = [touch locationInView:self.view];

  if (CGRectContainsPoint(targetRect, touchLocation)) {
    [self performSegueWithIdentifier:@"SEGUE_IDENTIFIER" sender:self];
  }
}