uinavigationItemバックボタンタッチエリアが大きすぎます
-
29-09-2019 - |
質問
この次のスクリーンショットでは、「利用可能なキオスク」から「V」をクリックすると、バックボタンのアクションが起動しています(2番目の「A」ではなく)。
理由がわかりません。コードに特別なものは何もありません(これは、ナビゲーションコントローラーによって処理されるデフォルトのバックボタンです)。また、私が行った別のアプリケーションと同じバグも持っていますが、他のアプリケーションでこれに気付くことはありません。
何か案は ?
ありがとうございました。
解決
それはバグではなく、Appleアプリでも同じことも、いくつかの(多くの /すべて?)ボタンでも同じです。それはボタン上のタッチイベントの動作です。タッチの領域はボタンの境界よりも大きくなります。
他のヒント
私は同じことをする必要があるので、uinavigationbar touchesbeganをスイズすることになりました。
これは、タッチがナビゲーションの下で使用していたボタンに近すぎると、キャンセルできることを意味します。
例:バックボタンは、ほとんど常に「最初」ボタンの代わりにタッチイベントをキャプチャしました
これが私のカテゴリーです:
@implementation UINavigationBar (UINavigationBarCategory)
- (void)sTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
float maxY = 0;
for (UITouch *touch in touches) {
float touchY = [touch locationInView:self].y;
if ( [touch locationInView:self].y > maxY) maxY = touchY;
}
NSLog(@"swizzlelichious bar touchY %f", maxY);
if (maxY < 35 )
[self sTouchesEnded:touches withEvent:event];
else
[self touchesCancelled:touches withEvent:event];
}
- (void)sTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
float maxY = 0;
for (UITouch *touch in touches) {
float touchY = [touch locationInView:self].y;
if ( [touch locationInView:self].y > maxY) maxY = touchY;
}
NSLog(@"swizzlelichious bar touchY %f", maxY);
if (maxY < 35 )
[self sTouchesBegan:touches withEvent:event];
else
[self touchesCancelled:touches withEvent:event];
}
Mike Ashからのスウィズルの実装 ココアデフ
void Swizzle(Class c, SEL orig, SEL new)
{
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, new);
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
else
method_exchangeImplementations(origMethod, newMethod);
}
関数はスウィズル関数を呼び出します
Swizzle([UINavigationBar class], @selector(touchesEnded:withEvent:), @selector(sTouchesEnded:withEvent:));
Swizzle([UINavigationBar class], @selector(touchesBegan:withEvent:), @selector(sTouchesBegan:withEvent:));
Appleがこれで問題ないかどうかはわかりませんが、UIガイドラインを侵害している可能性があります。アプリをApp Storeに提出した後に投稿を更新しようとします。
所属していません StackOverflow