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

4

13

I'm using the code below to hide the home indicator on iPhone X, which is working fine in the emulator.

-(BOOL)prefersHomeIndicatorAutoHidden
{
    return YES;
}

But even though it's hidden, I am still able to swipe up from the bottom and my game goes to the home screen.

I have seen a few games where the user has to swipe up once to bring up the home indicator and swipe up again to go to the home screen.

So, how can I force the user to swipe the home indicator twice to go to the home screen in iOS 11 with Objective-C?

This behavior is required for full-screen games.

Minimize answered 17/11, 2017 at 9:36 Comment(0)
J
15

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
}
Joann answered 19/10, 2018 at 14:14 Comment(1)
It is worth noting you can return .all if you want to restrict all gestures, like swiping down from top for Command Center.Praenomen
B
6

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.

Bield answered 17/12, 2017 at 19:31 Comment(1)
Yea forgot that one too. Though if the prefersHomeIndicatorAutoHidden returns 'yes' it still doesn't behave the right way, I am suprised it would let you just to defer without registering to received the deferred notificationCassandry
C
4

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

Cassandry answered 14/12, 2017 at 5:31 Comment(1)
"but not both" needs to be emphasizedFlex
V
0

This works for me :

-(bool) prefersHomeIndicatorAutoHidden {

return NO;

}
Villalpando answered 16/9, 2020 at 6:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.