如何滑动不同的离子标签
How to swipe through different ionic tabs
第一次 post 来到这里,但非常感谢对此的一些帮助或建议:
我目前正在使用 ionic 框架构建一个项目,在构建功能版本后,我决定能够在选项卡之间滑动以显示应用程序的各个部分。
我使用 ionic 提供的选项卡模板构建了应用程序,因此每个页面都通过 ion-nav-view 元素显示,并且是通过 app.js 文件中声明的状态更改调用的模板(见下文) :
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleLightContent();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
// setup an abstract state for the tabs directive
.state('tab', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
})
// Each tab has its own nav history stack:
.state('tab.dash', {
url: '/dash',
views: {
'tab-dash': {
templateUrl: 'templates/tab-dash.html',
}
}
})
.state('tab.notes', {
url: '/notes',
views: {
'tab-notes': {
templateUrl: 'templates/tab-notes.html',
controller: 'noteController'
}
}
})
.state('tab.todos', {
url: '/todos',
views: {
'tab-todos': {
templateUrl: 'templates/tab-todos.html',
controller: 'todoController'
}
}
})
.state('tab.doodles', {
url: '/doodles',
views: {
'tab-doodles': {
templateUrl: 'templates/tab-doodles.html',
}
}
})
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/tab/dash');
});
我想知道的是;有什么方法可以让用户左右滑动来切换不同的页面吗?
这可能吗?如果是这样,是否也需要滚动?
我希望这已经足够详细了,否则我会很乐意提供尽可能多的信息。感谢收听!
是的,这是可能的。我尝试了选项卡模板并得出以下结果:
<ion-content on-swipe-right="goBack()" on-swipe-left="goForward()">
并且在每个控制器中您将需要相应的功能:
.controller('MyCtrl', function ($scope, $ionicTabsDelegate) {
$scope.goForward = function () {
var selected = $ionicTabsDelegate.selectedIndex();
if (selected != -1) {
$ionicTabsDelegate.select(selected + 1);
}
}
$scope.goBack = function () {
var selected = $ionicTabsDelegate.selectedIndex();
if (selected != -1 && selected != 0) {
$ionicTabsDelegate.select(selected - 1);
}
}
})
我不知道这是否是最佳实践并且非常可靠。就像我说的,我只是在阅读 docs.
之后玩了一下
我希望我让您了解它是如何工作的。
第一次 post 来到这里,但非常感谢对此的一些帮助或建议:
我目前正在使用 ionic 框架构建一个项目,在构建功能版本后,我决定能够在选项卡之间滑动以显示应用程序的各个部分。
我使用 ionic 提供的选项卡模板构建了应用程序,因此每个页面都通过 ion-nav-view 元素显示,并且是通过 app.js 文件中声明的状态更改调用的模板(见下文) :
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleLightContent();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
// setup an abstract state for the tabs directive
.state('tab', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
})
// Each tab has its own nav history stack:
.state('tab.dash', {
url: '/dash',
views: {
'tab-dash': {
templateUrl: 'templates/tab-dash.html',
}
}
})
.state('tab.notes', {
url: '/notes',
views: {
'tab-notes': {
templateUrl: 'templates/tab-notes.html',
controller: 'noteController'
}
}
})
.state('tab.todos', {
url: '/todos',
views: {
'tab-todos': {
templateUrl: 'templates/tab-todos.html',
controller: 'todoController'
}
}
})
.state('tab.doodles', {
url: '/doodles',
views: {
'tab-doodles': {
templateUrl: 'templates/tab-doodles.html',
}
}
})
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/tab/dash');
});
我想知道的是;有什么方法可以让用户左右滑动来切换不同的页面吗?
这可能吗?如果是这样,是否也需要滚动?
我希望这已经足够详细了,否则我会很乐意提供尽可能多的信息。感谢收听!
是的,这是可能的。我尝试了选项卡模板并得出以下结果:
<ion-content on-swipe-right="goBack()" on-swipe-left="goForward()">
并且在每个控制器中您将需要相应的功能:
.controller('MyCtrl', function ($scope, $ionicTabsDelegate) {
$scope.goForward = function () {
var selected = $ionicTabsDelegate.selectedIndex();
if (selected != -1) {
$ionicTabsDelegate.select(selected + 1);
}
}
$scope.goBack = function () {
var selected = $ionicTabsDelegate.selectedIndex();
if (selected != -1 && selected != 0) {
$ionicTabsDelegate.select(selected - 1);
}
}
})
我不知道这是否是最佳实践并且非常可靠。就像我说的,我只是在阅读 docs.
之后玩了一下我希望我让您了解它是如何工作的。