iPhone-X - 如何强制用户刷两次家用指示灯进入主屏幕

问题描述 投票:9回答:3

我正在使用下面的代码隐藏iPhone X上的主页指示器,这在模拟器中工作正常。

-(BOOL)prefersHomeIndicatorAutoHidden
{
    return YES;
}

但即使它被隐藏了,我仍然可以从底部向上滑动,我的游戏进入主屏幕。

我已经看过几个游戏,用户必须向上滑动一次以调出家庭指示器并再次向上滑动以进入主屏幕。

那么,如何强制用户滑动主页指示两次以使用Objective-C转到iOS 11的主屏幕?

全屏游戏需要此行为。

ios ios11 iphone-x
3个回答
9
投票

had the same problem

PrefersHomeIndicatorAutoHidden必须返回NO,但PreferredScreenEdgesDeferringSystemGestures必须被覆盖并返回UIRectEdgeBottom

Swift 4.2

override var prefersHomeIndicatorAutoHidden: Bool {
  return false
}

override var preferredScreenEdgesDeferringSystemGestures: UIRectEdge {
  return UIRectEdge.bottom
}

5
投票

将以下内容添加到ViewController为我做了诀窍:

- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
    return UIRectEdgeBottom;
}

这使得家庭指示器更加透明和不活动,因此需要额外的滑动才能离开游戏。

您还可以使用UIRectEdgeAll而不是UIRectEdgeBottom来推迟屏幕所有边缘的系统手势。


3
投票

它是隐藏和延迟之间的选择,但不是两者之间的选择

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

在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]; 

并定义handleGesture,无需为此工作做任何事情

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

    NSLog(@"gestured");
}

应该是它

© www.soinside.com 2019 - 2024. All rights reserved.