プロパティを使用して、タップが発生した場所を特定し、条件付きでメソッドを呼び出すことができます。ヒットエリアに対応するCGRect
を設定することで、これを行うことができます。次に、CGRectContainsPoint()
関数を使用して、タップがヒット領域の1つに着陸したかどうかを判断します。
あなたのタップジェスチャー認識のアクションは、次のようになります。私のために働いた
- (void)tapGestureRecognized:(UIGestureRecognizer *)recognizer
{
// Specify some CGRects that will be hit areas
CGRect firstHitArea = CGRectMake(10.0f, 10.0f, 44.0f, 44.0f);
CGRect secondHitArea = CGRectMake(64.0f, 10.0f, 44.0f, 44.0f)
// Get the location of the touch in the view's coordinate space
CGPoint touchLocation = [recognizer locationInView:recognizer.view];
if (CGRectContainsPoint(firstHitArea, touchLocation))
{
[self firstMethod];
}
else if (CGRectContainsPoint(secondHitArea, touchLocation))
{
[self secondMethod];
}
}
、感謝を! –