iPhone-X - How to force user to swipe twice home indicator to go home-screen

大城市里の小女人 提交于 2019-12-03 02:58:49
filo

I had the same problem.

PrefersHomeIndicatorAutoHidden must return NO but also PreferredScreenEdgesDeferringSystemGestures must be overridden and return UIRectEdgeBottom.

Swift 4.2

override var prefersHomeIndicatorAutoHidden: Bool {
  return false
}

override var preferredScreenEdgesDeferringSystemGestures: UIRectEdge {
  return UIRectEdge.bottom
}

Adding the following to the ViewController did the trick for me:

- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
    return UIRectEdgeBottom;
}

This made the Home Indicator more transparent and inactivated so that it requires an extra swipe in order to leave the game.

You can also use UIRectEdgeAll instead of UIRectEdgeBottom to defer the system gestures on all edges of the screen.

It is a choice between hidden and deferred but NOT both

-(BOOL)prefersHomeIndicatorAutoHidden
{
    // YES for hidden (but swipe activated)
    // NO for deferred (app gets priority gesture notification)
    return NO;  
}

register the gesture in viewDidLoad

UIScreenEdgePanGestureRecognizer *sePanGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
sePanGesture.edges = UIRectEdgeAll; 
// or just set the bottom if you prefer, top-right seems to behave well by default
[self.view addGestureRecognizer:sePanGesture]; 

and define the handleGesture, no need to do anything there for this to work

- (void)handleGesture:(UIScreenEdgePanGestureRecognizer *)recognizer {
    // to get location where the first touch occurred from docs
    // CGPoint location = [recognizer locationInView:[recognizer.view superview]]; 

    NSLog(@"gestured");
}

should be it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!