さて、私が言いたいことを示すのが最善だと思います:
ボタンに触れてそこから移動すると、その結果の移動イベントがボタンの状態の変化を遠くからトリガーすることがはっきりとわかります。
この動作はすべての UIButton で自然ですが、それを変更するための解決策をグーグルで検索することはできませんでした。
このタイプの UIButton 感度のヒット領域を減らす方法はありますか? ボタンはそのままで十分大きく、上下の効果音とともにユーザーエクスペリエンスが向上すると思うので、減らしてほしいです。
UPD: UIButton の次のオーバーライド コードが別のスレッドに投稿されました。
- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
CGFloat boundsExtension = 25.0f;
CGRect outerBounds = CGRectInset(self.bounds, -1 * boundsExtension, -1 * boundsExtension);
BOOL touchOutside = !CGRectContainsPoint(outerBounds, [touch locationInView:self]);
if(touchOutside)
{
BOOL previousTouchInside = CGRectContainsPoint(outerBounds, [touch previousLocationInView:self]);
if(previousTouchInside)
{
NSLog(@"Sending UIControlEventTouchDragExit");
[self sendActionsForControlEvents:UIControlEventTouchDragExit];
}
else
{
NSLog(@"Sending UIControlEventTouchDragOutside");
[self sendActionsForControlEvents:UIControlEventTouchDragOutside];
}
}
return [super continueTrackingWithTouch:touch withEvent:event];
}
Drag In/Drag Out イベントで使用されるヒット領域の拡張を変更しますが、ボタンの Up/Down 状態は以前とまったく同じように切り替わります。