使用ionic開發app的時候,會發現切換頁面的動畫會卡頓,并不流暢,為了保證用戶體驗,大部分人會使用禁用動畫的方法$ionicConfigProvider.views.transition('no');,但并不是最好的解決思路,cordova提供了native transitions可以讓頁面切換近乎原型的體驗。主要步驟如下:
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里,切面切換的效果會比ionic自帶的要流暢不少;
注意:頁面切換的方向,后退<ion-nav-back-button>默認是左往右,其他則是右往左,有時候你可能并不用<ion-nav-back-button>這個標簽,而是使用<ion-nav-bar>該標簽,后退加自定義的東西,這時后退是按右往左,那怎樣左往右了,用$rootScope.$ionicGoBack();就可以,而不要使用$ionicHistory.goBack();之后的后退方法。
更多的可以看下這個地址
https://github.com/shprink/ionic-native-transitions
以上所述是小編給大家介紹的使用ionic切換頁面卡頓的解決方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VeVb武林網網站的支持!
新聞熱點
疑難解答