Nativescript IPhone X-如何“隐藏”两次滑动后的主屏幕指示器以返回主屏幕

时间:2019-06-13 01:58:51

标签: ios xcode nativescript nativescript-angular

我正在使用Nativescript Angular(NS版本4.1),我正在尝试实施一项要求用户向上滑动两次以返回首页的要求 新的IOS设备。许多手机游戏都具有此功能。

我知道这与prefersHomeIndicatorAutoHidden有关,并且 preferredScreenEdgesDeferringSystemGestures中的ViewController 有没有办法可以在Nativescript Angular中访问这些方法? 还是只是设置一个首页指示器,需要两次滑动才能返回首页?

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:2)

有一个开放的feature request,可以覆盖iOS根视图控制器属性。您实际上必须将preferredScreenEdgesDeferringSystemGestures改写为UIRectEdge.All,并且根据Apple documentation,还必须更新setneedsupdateofhomeindicator

但是,如果您尝试直接访问这些属性(例如this.page.ios.prefersHomeIndicatorAutoHidden = true),则会出现错误TypeError: Attempted to assign to readonly property.

这些是here中讨论的解决方法,您可以在其中复制控制器,修改属性并将其分配回所有者。

const UIViewControllerImpl = new page.Page().ios.constructor as typeof UIViewController;

    const MyCustumUIViewController = UIViewController['extend'](Object.assign(
      {},
      // merge in the original methods
      ...UIViewControllerImpl.prototype,
      // add additional instance method / property overrides here, such as ...
      {
        preferredScreenEdgesDeferringSystemGestures() {
            console.log("This will be called from native!");
            return UIRectEdge.All;
        }
      }
    ));

    const performNavigation = frame.Frame.prototype['performNavigation'];
    frame.Frame.prototype['performNavigation'] = function(navigationContext:{entry:frame.BackstackEntry}) {
        const page = navigationContext.entry.resolvedPage;
        const controller = (<typeof UIViewController>MyCustumUIViewController).new();
        controller['_owner'] = new WeakRef(page);
        controller.automaticallyAdjustsScrollViewInsets = false;
        controller.view.backgroundColor = new color.Color("white").ios;
        page['_ios'] = controller;
        page.setNativeView(controller.view);
        performNavigation.call(this, navigationContext);
    }