Skip to content

Commit ee6685d

Browse files
committed
按钮动态效果
1 parent 9f5567a commit ee6685d

File tree

4 files changed

+119
-3
lines changed

4 files changed

+119
-3
lines changed

app/components/example/Main.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
<Button class="btn btn-primary m-t-20" text="animateCSS" @tap="animate" />
2626
<Button class="btn btn-primary m-t-20" text="下拉刷新" @tap="refresh" />
2727
<Button class="btn btn-primary m-t-20" text="下拉刷新❤新" @tap="refreshNew" />
28+
<Button class="btn btn-primary m-t-20" text="触摸事件" @tap="touch" />
2829
</StackLayout>
29-
3030
<!-- </GridLayout> -->
31-
3231
</ScrollView>
3332
</Page>
3433
</template>
@@ -50,6 +49,7 @@ import Pop from "./pop";
5049
import Animate from "./animate";
5150
import Refresh from "./refresh";
5251
import RefreshNew from "./refreshNew";
52+
import Touch from "./touch";
5353
5454
export default {
5555
data () {
@@ -59,6 +59,9 @@ export default {
5959
},
6060
mounted () { },
6161
methods: {
62+
touch: function () {
63+
this.$navigateTo(Touch);
64+
},
6265
refreshNew: function () {
6366
this.$navigateTo(RefreshNew);
6467
},

app/components/example/refreshNew.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,23 @@ export default {
3535
num: 0,
3636
isStart: false,
3737
isTime: true,
38+
//下拉信息
39+
pull_to_refresh:'下拉可以刷新',
40+
release_to_refresh:'释放立即刷新',
41+
refreshing:'正在刷新…',
42+
not_updated_yet:'暂未更新过',
43+
updated_at:'上次更新于%1$s前',
44+
updated_just_now:'刚刚更新',
45+
time_error:'时间有问题'
3846
};
3947
},
4048
mounted () {
4149
this.pageLoaded();
4250
},
4351
methods: {
52+
setIsAbleToPull:function(){
53+
54+
},
4455
pageLoaded: function (args) {
4556
4657
},
@@ -73,7 +84,7 @@ export default {
7384
onDrawerPan (side, args) {
7485
let ht = this.$refs.ht.nativeView;
7586
if (ht.marginTop < 0 && this.isStart) {
76-
ht.marginTop = ht.marginTop + 5;
87+
ht.marginTop = ht.marginTop + 1;
7788
} else {
7889
if (this.isTime) {
7990
this.isTime = false;

app/components/example/touch.vue

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<template>
2+
<Page loaded="pageLoaded" ref="page">
3+
<ActionBar class="action-bar" title="Hello">
4+
<NavigationButton text="Go Back" android.systemIcon="ic_menu_back" @tap="$navigateBack" />
5+
</ActionBar>
6+
<GridLayout colums="*" rows="*">
7+
<Button class="btn btn-primary m-t-20" ref="btn" text="触摸" @tap="touch" />
8+
</GridLayout>
9+
</Page>
10+
</template>
11+
12+
<script>
13+
14+
export default {
15+
data () {
16+
return {
17+
msg: "Hello World! ",
18+
glyphs: []
19+
};
20+
},
21+
mounted () {
22+
},
23+
methods: {
24+
touch: function () {
25+
26+
let btn = this.$refs.btn.nativeView;
27+
console.log('');
28+
btn.android.setOnTouchListener(new android.view.View.OnTouchListener({
29+
onTouch: function (view, motionEvent) {
30+
// var action = motionEvent.getAction();
31+
// if (action === android.view.MotionEvent.ACTION_DOWN) {
32+
// console.log('######')
33+
// }
34+
// if (action === android.view.MotionEvent.ACTION_UP) {
35+
// console.log('@@@@@@')
36+
// }
37+
// return false;
38+
let scale = '0.7f'
39+
let duration = 150;
40+
let interpolator= new android.view.animation.DecelerateInterpolator();
41+
//按钮点击效果
42+
let v = view;
43+
let event = motionEvent;
44+
let MotionEvent = android.view.MotionEvent;
45+
switch (event.getAction()) {
46+
case MotionEvent.ACTION_DOWN:
47+
console.log('按下了');
48+
v.animate().scaleX(scale).scaleY(scale).setDuration(duration).setInterpolator(interpolator);
49+
v.setPressed(true);
50+
break;
51+
52+
case MotionEvent.ACTION_MOVE:
53+
let x = event.getX();
54+
let y = event.getY();
55+
let isInside = (x > 0 && x < v.getWidth() && y > 0 && y < v.getHeight());
56+
if (v.isPressed() != isInside) {
57+
v.setPressed(isInside);
58+
}
59+
break;
60+
case MotionEvent.ACTION_CANCEL:
61+
v.setPressed(false);
62+
v.animate().scaleX(1).scaleY(1).setInterpolator(interpolator);
63+
break;
64+
case MotionEvent.ACTION_UP:
65+
v.animate().scaleX(1).scaleY(1).setInterpolator(interpolator);
66+
if (v.isPressed()) {
67+
v.performClick();
68+
v.setPressed(false);
69+
}
70+
break;
71+
}
72+
return true;
73+
}
74+
}));
75+
console.log('点击了触摸');
76+
}
77+
}
78+
};
79+
</script>
80+
81+
<style scoped>
82+
ActionBar {
83+
background-color: #53ba82;
84+
color: #ffffff;
85+
}
86+
87+
.message {
88+
vertical-align: center;
89+
text-align: center;
90+
font-size: 20;
91+
color: #333333;
92+
}
93+
.icons {
94+
font-family: "icomoon";
95+
font-size: 48;
96+
}
97+
.icon {
98+
font-family: iconfont;
99+
font-size: 48;
100+
}
101+
</style>

app/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import store from './store';
55
import { prototype } from 'stream';
66
//import VueDevtools from 'nativescript-vue-devtools'
77

8+
89
const application = require('tns-core-modules/application');
910

1011
// Vue.use(VueDevtools)

0 commit comments

Comments
 (0)