使用ionic開(kāi)發(fā)app的時(shí)候,會(huì)發(fā)現(xiàn)切換頁(yè)面的動(dòng)畫會(huì)卡頓,并不流暢,為了保證用戶體驗(yàn),大部分人會(huì)使用禁用動(dòng)畫的方法$ionicConfigProvider.views.transition('no');,但并不是最好的解決思路,cordova提供了native transitions可以讓頁(yè)面切換近乎原型的體驗(yàn)。主要步驟如下:
1、npm install ionic-native-transitions --save 下載該文件,并放入www/lib文件夾下
2、在index.html中加入<script src="lib/ionic-native-transitions/dist/ionic-native-transitions.min.js"></script>
2、cordova plugin add cordvoa-plugin-NativePageTransitions安裝該插件
3、在app.js中引入'ionic-native-transitions'配置如下信息并禁用$ionicConfigProvider.views.transition('no');
$ionicNativeTransitionsProvider.setDefaultOptions({ duration: 400, // in milliseconds (ms), default 400, slowdownfactor: 4, // overlap views (higher number is more) or no overlap (1), default 4 iosdelay: -1, // ms to wait for the iOS webview to update before animation kicks in, default -1 androiddelay: -1, // same as above but for Android, default -1 winphonedelay: -1, // same as above but for Windows Phone, default -1, fixedPixelsTop: 0, // the number of pixels of your fixed header, default 0 (iOS and Android) fixedPixelsBottom: 0, // the number of pixels of your fixed footer (f.i. a tab bar), default 0 (iOS and Android) triggerTransitionEvent: '$ionicView.afterEnter', // internal ionic-native-transitions option backInOppositeDirection: false // Takes over default back transition and state back transition to use the opposite direction transition to go back }); 這樣在打包成的app里,切面切換的效果會(huì)比ionic自帶的要流暢不少;
注意:頁(yè)面切換的方向,后退<ion-nav-back-button>默認(rèn)是左往右,其他則是右往左,有時(shí)候你可能并不用<ion-nav-back-button>這個(gè)標(biāo)簽,而是使用<ion-nav-bar>該標(biāo)簽,后退加自定義的東西,這時(shí)后退是按右往左,那怎樣左往右了,用$rootScope.$ionicGoBack();就可以,而不要使用$ionicHistory.goBack();之后的后退方法。
更多的可以看下這個(gè)地址
https://github.com/shprink/ionic-native-transitions
以上所述是小編給大家介紹的使用ionic切換頁(yè)面卡頓的解決方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注