【SDK fix】iOS 8でUIButtonをtabbar位置に置くとeventに応答できません

1658 ワード

このblogは一部の訳文を除いて、すべての内容はすべてオリジナルで、もし同じならば、私はあなたを写します:-)

問題の説明


問題はiOS UIButtonのtouchDownイベントという投稿から来ています.簡単に言えば、設定
objcdetailVC.hidesBottomBarWhenPushed = YES;

その後、viewをtabbarの元の位置に置いてviewにbuttonを追加し、buttonにtouchDown actionを追加し、buttonの左下隅領域を押すとactionはトリガーされません.

トリガ環境


iOS 7以上、本体をデバッグします.

分析プロセス


HitTestの結果を先に確認するとbuttonインスタンスが正しく返されます.これはbuttonが透明なviewに覆われていないことを示している.次に、override buttonのtouchesXXXメソッド.buttonの左下を押すとtouchesBeganなど4つのメソッドは全く呼び出されません.次の図を参照すると、gesture recognizerが存在し、delaysTouchesBeganがYESに設定されているはずです.
delaysTouchesBegan (default of NO)—Normally, the window sends touch objects in the Began and Moved phases to the view and the gesture recognizer. Setting delaysTouchesBegan to YES prevents the window from delivering touch objects in the Began phase to the view. This ensures that when a gesture recognizer recognizes its gesture, no part of the touch event was delivered to the attached view. Be cautious when setting this property because it can make your interface feel unresponsive.
現在のシーンを考えると、スライドしてジェスチャーを返す鬼のはずです.ちょっと検証して
objc- (void)viewDidLoad
{
    //Other codes here
    NSLog(@"%d", self.navigationController.interactivePopGestureRecognizer.delaysTouchesBegan);
}

結果を得ると答えが明らかになります.

ソリューション

objcself.navigationController.interactivePopGestureRecognizer.delaysTouchesBegan = NO;

Demo


Button touch down bug fix

参考資料


Placing a UIButton in the same space as UITabBar (When hidden)