Ionic 3可以向单页滑动 [英] Ionic 3 enable swipe back for a single page

查看:539
本文介绍了Ionic 3可以向单页滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在全局禁用'向后扫',包括根组件和模块配置

I've disabled 'swipe back' globally, both in root component and module config

<ion-nav #appNav [root]="rootPage" swipeBackEnabled="false"></ion-nav>

...
IonicModule.forRoot(MobileApplication, {swipeBackEnabled: false}),
...

我只需要为一页启用它。所以试图通过将一个导航实例传递给构造函数然后将swipeBackEnabled设置为true来设置它。

I need though to enable it for one page only. So'm trying to set it by passing a nav instance to constructor and then setting swipeBackEnabled to true.

ionViewWillEnter() {
    this.nav.swipeBackEnabled = true;
    console.log('swipeBackEnabled ' + this.nav.swipeBackEnabled);
    console.log('canGoBack ' + this.nav.canGoBack());
    console.log('canSwipeBack ' + this.nav.canSwipeBack());
}

记录swipeBackEnabled并且canGoBack返回true,但canSwipeBack返回false。如果我在模板中的某处添加滑动事件并在右侧滑动时记录这些值,则会将所有值记录为true。然而,没有任何反应,似乎刷回不起作用?我错过了什么吗?

Logging swipeBackEnabled and canGoBack returns true, but canSwipeBack returns false. If I add a swipe event somewhere in my template and log those values on right swipe, it logs all the values as true. However, nothing happens, seems like swipe back is not working? Am I missing something?

作为参考,我使用的是Ionic 3.9.2和@ ionic / app-scripts 3.1.4。在此先感谢

For reference, I'm using Ionic 3.9.2 and @ionic/app-scripts 3.1.4. Thanks in advance

推荐答案

我不完全确定这里的诀窍是什么,但以下设置使它对我有用:

I'm not completely sure what did the trick here, but the following setup made it work for me:

public ionViewWillEnter(): void {
    this.appNav.swipeBackEnabled = true;
}

public ionViewDidLeave(): void {
    this.appNav.swipeBackEnabled = false;
}

appNav这是离子NavController的一个实例。我还没有完全理解为什么在其他生命周期钩子中设置swipeBackEnabled没有成功,所以我稍后会继续调查。对于可能遇到相同问题的人来说,这可能是一个起点。

appNav here is an instance of ionic NavController. I don't yet fully understand why setting swipeBackEnabled in other lifecycle hooks didn't make it, so I'll continue investigating later on. This might be a starting point for someone who might encounter same issue though.

这篇关于Ionic 3可以向单页滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆