ionic 是否有滑动或其他事件的指令?
我找到了这项服务:$ionicGesture
。我应该用这个制定自己的指令吗?
或者我应该使用其他类似 ngTouch 的东西吗?
ionic 是否有滑动或其他事件的指令?
我找到了这项服务:$ionicGesture
。我应该用这个制定自己的指令吗?
或者我应该使用其他类似 ngTouch 的东西吗?
当这个问题处于活动状态时,似乎不存在滑动指令,但它们现在可用:http: //ionicframework.com/docs/api/directive/onSwipe/
<button on-swipe="onSwipe()" class="button">Test</button>
也可用:on-swipe-left
、on-swipe-right
和。on-swipe-up
on-swipe-down
没有任何开箱即用的滑动指令,但由于事件是公开的,因此将一些东西放在一起非常简单。
.directive('detectGestures', function($ionicGesture) {
return {
restrict : 'A',
link : function(scope, elem, attrs) {
var gestureType = attrs.gestureType;
switch(gestureType) {
case 'swipe':
$ionicGesture.on('swipe', scope.reportEvent, elem);
break;
case 'swiperight':
$ionicGesture.on('swiperight', scope.reportEvent, elem);
break;
case 'swipeleft':
$ionicGesture.on('swipeleft', scope.reportEvent, elem);
break;
case 'doubletap':
$ionicGesture.on('doubletap', scope.reportEvent, elem);
break;
case 'tap':
$ionicGesture.on('tap', scope.reportEvent, elem);
break;
}
}
}
})
有一个很棒的教程解释了如何使用 Ionicframework 和 AngularJS http://ionicframework.com/blog/ionic-swipeable-cards/
基本上,您将使用 Ionicframework 对象/函数(如下面的片段)创建一个视图,并创建一个将调用它的指令。请参阅教程中的详细信息。
var SwipeableCardView = ionic.views.View.inherit({
initialize: function(opts) {
// Store the card element
this.el = opts.el;
this.bindEvents();
},
bindEvents: function() {
var self = this;
ionic.onGesture('drag', function(e) {
// Process drag
}, this.el);
ionic.onGesture('dragend', function(e) {
// Process end of drag
}, this.el);
},