更新ScrolView的例子,添加滑动事件

This commit is contained in:
leo
2018-06-06 10:36:49 +08:00
parent 7462d276db
commit 6e3552b7d1
32 changed files with 218 additions and 21847 deletions

View File

@@ -45,7 +45,7 @@
"_globalZOrder": 0,
"_opacityModifyRGB": false,
"groupIndex": 0,
"autoReleaseAssets": null
"autoReleaseAssets": false
},
{
"__type__": "cc.Node",
@@ -65,23 +65,23 @@
"__id__": 8
},
{
"__id__": 23
"__id__": 24
},
{
"__id__": 40
"__id__": 42
},
{
"__id__": 57
"__id__": 60
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 77
"__id__": 80
},
{
"__id__": 78
"__id__": 81
}
],
"_prefab": null,
@@ -886,11 +886,24 @@
"brake": 0.75,
"elastic": true,
"bounceDuration": 0.23,
"scrollEvents": [],
"scrollEvents": [
{
"__id__": 23
}
],
"cancelInnerEvents": true,
"_N$horizontalScrollBar": null,
"_N$verticalScrollBar": null
},
{
"__type__": "cc.ClickEvent",
"target": {
"__id__": 2
},
"component": "HelloWorld",
"handler": "onEventScrollView",
"customEventData": ""
},
{
"__type__": "cc.Node",
"_name": "vertical",
@@ -900,20 +913,20 @@
},
"_children": [
{
"__id__": 24
"__id__": 25
},
{
"__id__": 30
"__id__": 31
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 38
"__id__": 39
},
{
"__id__": 39
"__id__": 40
}
],
"_prefab": null,
@@ -958,24 +971,24 @@
"_name": "scrollBar",
"_objFlags": 0,
"_parent": {
"__id__": 23
"__id__": 24
},
"_children": [
{
"__id__": 25
"__id__": 26
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 27
},
{
"__id__": 28
},
{
"__id__": 29
},
{
"__id__": 30
}
],
"_prefab": null,
@@ -1020,14 +1033,14 @@
"_name": "bar",
"_objFlags": 0,
"_parent": {
"__id__": 24
"__id__": 25
},
"_children": [],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 26
"__id__": 27
}
],
"_prefab": null,
@@ -1072,7 +1085,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 25
"__id__": 26
},
"_enabled": true,
"_spriteFrame": {
@@ -1098,7 +1111,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 24
"__id__": 25
},
"_enabled": true,
"_scrollView": {
@@ -1109,7 +1122,7 @@
"enableAutoHide": true,
"autoHideTime": 1,
"_N$handle": {
"__id__": 26
"__id__": 27
},
"_N$direction": 1
},
@@ -1118,7 +1131,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 24
"__id__": 25
},
"_enabled": true,
"isAlignOnce": true,
@@ -1144,7 +1157,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 24
"__id__": 25
},
"_enabled": true,
"_spriteFrame": {
@@ -1170,18 +1183,18 @@
"_name": "view",
"_objFlags": 0,
"_parent": {
"__id__": 23
"__id__": 24
},
"_children": [
{
"__id__": 31
"__id__": 32
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 37
"__id__": 38
}
],
"_prefab": null,
@@ -1226,21 +1239,21 @@
"_name": "content",
"_objFlags": 0,
"_parent": {
"__id__": 30
"__id__": 31
},
"_children": [
{
"__id__": 32
"__id__": 33
},
{
"__id__": 34
"__id__": 35
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 36
"__id__": 37
}
],
"_prefab": null,
@@ -1285,14 +1298,14 @@
"_name": "HelloWorld",
"_objFlags": 0,
"_parent": {
"__id__": 31
"__id__": 32
},
"_children": [],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 33
"__id__": 34
}
],
"_prefab": null,
@@ -1337,7 +1350,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 32
"__id__": 33
},
"_enabled": true,
"_spriteFrame": {
@@ -1363,14 +1376,14 @@
"_name": "HelloWorld",
"_objFlags": 0,
"_parent": {
"__id__": 31
"__id__": 32
},
"_children": [],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 35
"__id__": 36
}
],
"_prefab": null,
@@ -1415,7 +1428,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 34
"__id__": 35
},
"_enabled": true,
"_spriteFrame": {
@@ -1441,7 +1454,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 31
"__id__": 32
},
"_enabled": true,
"_layoutSize": {
@@ -1472,7 +1485,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 30
"__id__": 31
},
"_enabled": true,
"_type": 0,
@@ -1486,7 +1499,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 23
"__id__": 24
},
"_enabled": true,
"_spriteFrame": {
@@ -1512,11 +1525,11 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 23
"__id__": 24
},
"_enabled": true,
"content": {
"__id__": 31
"__id__": 32
},
"horizontal": false,
"vertical": true,
@@ -1524,13 +1537,26 @@
"brake": 0.75,
"elastic": true,
"bounceDuration": 0.23,
"scrollEvents": [],
"scrollEvents": [
{
"__id__": 41
}
],
"cancelInnerEvents": true,
"_N$horizontalScrollBar": null,
"_N$verticalScrollBar": {
"__id__": 27
"__id__": 28
}
},
{
"__type__": "cc.ClickEvent",
"target": {
"__id__": 2
},
"component": "HelloWorld",
"handler": "onEventScrollView",
"customEventData": ""
},
{
"__type__": "cc.Node",
"_name": "grid",
@@ -1540,17 +1566,17 @@
},
"_children": [
{
"__id__": 41
"__id__": 43
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 55
"__id__": 57
},
{
"__id__": 56
"__id__": 58
}
],
"_prefab": null,
@@ -1595,18 +1621,18 @@
"_name": "view",
"_objFlags": 0,
"_parent": {
"__id__": 40
"__id__": 42
},
"_children": [
{
"__id__": 42
"__id__": 44
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 54
"__id__": 56
}
],
"_prefab": null,
@@ -1651,12 +1677,9 @@
"_name": "content",
"_objFlags": 0,
"_parent": {
"__id__": 41
"__id__": 43
},
"_children": [
{
"__id__": 43
},
{
"__id__": 45
},
@@ -1668,13 +1691,16 @@
},
{
"__id__": 51
},
{
"__id__": 53
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 53
"__id__": 55
}
],
"_prefab": null,
@@ -1719,14 +1745,14 @@
"_name": "HelloWorld",
"_objFlags": 0,
"_parent": {
"__id__": 42
"__id__": 44
},
"_children": [],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 44
"__id__": 46
}
],
"_prefab": null,
@@ -1771,7 +1797,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 43
"__id__": 45
},
"_enabled": true,
"_spriteFrame": {
@@ -1797,14 +1823,14 @@
"_name": "HelloWorld",
"_objFlags": 0,
"_parent": {
"__id__": 42
"__id__": 44
},
"_children": [],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 46
"__id__": 48
}
],
"_prefab": null,
@@ -1849,7 +1875,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 45
"__id__": 47
},
"_enabled": true,
"_spriteFrame": {
@@ -1875,14 +1901,14 @@
"_name": "HelloWorld",
"_objFlags": 0,
"_parent": {
"__id__": 42
"__id__": 44
},
"_children": [],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 48
"__id__": 50
}
],
"_prefab": null,
@@ -1927,7 +1953,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 47
"__id__": 49
},
"_enabled": true,
"_spriteFrame": {
@@ -1953,14 +1979,14 @@
"_name": "HelloWorld",
"_objFlags": 0,
"_parent": {
"__id__": 42
"__id__": 44
},
"_children": [],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 50
"__id__": 52
}
],
"_prefab": null,
@@ -2005,7 +2031,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 49
"__id__": 51
},
"_enabled": true,
"_spriteFrame": {
@@ -2031,14 +2057,14 @@
"_name": "HelloWorld",
"_objFlags": 0,
"_parent": {
"__id__": 42
"__id__": 44
},
"_children": [],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 52
"__id__": 54
}
],
"_prefab": null,
@@ -2083,7 +2109,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 51
"__id__": 53
},
"_enabled": true,
"_spriteFrame": {
@@ -2109,7 +2135,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 42
"__id__": 44
},
"_enabled": true,
"_layoutSize": {
@@ -2140,7 +2166,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 41
"__id__": 43
},
"_enabled": true,
"_type": 0,
@@ -2154,7 +2180,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 40
"__id__": 42
},
"_enabled": true,
"_spriteFrame": {
@@ -2180,11 +2206,11 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 40
"__id__": 42
},
"_enabled": true,
"content": {
"__id__": 42
"__id__": 44
},
"horizontal": false,
"vertical": true,
@@ -2192,11 +2218,24 @@
"brake": 0.75,
"elastic": true,
"bounceDuration": 0.23,
"scrollEvents": [],
"scrollEvents": [
{
"__id__": 59
}
],
"cancelInnerEvents": true,
"_N$horizontalScrollBar": null,
"_N$verticalScrollBar": null
},
{
"__type__": "cc.ClickEvent",
"target": {
"__id__": 2
},
"component": "HelloWorld",
"handler": "onEventScrollView",
"customEventData": ""
},
{
"__type__": "cc.Node",
"_name": "Btn",
@@ -2206,20 +2245,20 @@
},
"_children": [
{
"__id__": 58
"__id__": 61
},
{
"__id__": 64
"__id__": 67
},
{
"__id__": 70
"__id__": 73
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 76
"__id__": 79
}
],
"_prefab": null,
@@ -2264,21 +2303,21 @@
"_name": "btn0",
"_objFlags": 0,
"_parent": {
"__id__": 57
"__id__": 60
},
"_children": [
{
"__id__": 59
"__id__": 62
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 61
"__id__": 64
},
{
"__id__": 62
"__id__": 65
}
],
"_prefab": null,
@@ -2323,14 +2362,14 @@
"_name": "Label",
"_objFlags": 0,
"_parent": {
"__id__": 58
"__id__": 61
},
"_children": [],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 60
"__id__": 63
}
],
"_prefab": null,
@@ -2375,7 +2414,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 59
"__id__": 62
},
"_enabled": true,
"_useOriginalSize": false,
@@ -2397,7 +2436,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 58
"__id__": 61
},
"_enabled": true,
"_spriteFrame": {
@@ -2423,7 +2462,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 58
"__id__": 61
},
"_enabled": true,
"transition": 2,
@@ -2443,15 +2482,9 @@
},
"duration": 0.1,
"zoomScale": 1.2,
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"hoverSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"clickEvents": [
{
"__id__": 63
"__id__": 66
}
],
"_N$interactable": true,
@@ -2473,11 +2506,23 @@
"_N$normalSprite": {
"__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952"
},
"_N$pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"_N$hoverSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"hoverSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"_N$disabledSprite": {
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 58
"__id__": 61
}
},
{
@@ -2494,21 +2539,21 @@
"_name": "btn1",
"_objFlags": 0,
"_parent": {
"__id__": 57
"__id__": 60
},
"_children": [
{
"__id__": 65
"__id__": 68
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 67
"__id__": 70
},
{
"__id__": 68
"__id__": 71
}
],
"_prefab": null,
@@ -2553,14 +2598,14 @@
"_name": "Label",
"_objFlags": 0,
"_parent": {
"__id__": 64
"__id__": 67
},
"_children": [],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 66
"__id__": 69
}
],
"_prefab": null,
@@ -2605,7 +2650,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 65
"__id__": 68
},
"_enabled": true,
"_useOriginalSize": false,
@@ -2627,7 +2672,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 64
"__id__": 67
},
"_enabled": true,
"_spriteFrame": {
@@ -2653,7 +2698,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 64
"__id__": 67
},
"_enabled": true,
"transition": 2,
@@ -2673,15 +2718,9 @@
},
"duration": 0.1,
"zoomScale": 1.2,
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"hoverSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"clickEvents": [
{
"__id__": 69
"__id__": 72
}
],
"_N$interactable": true,
@@ -2703,11 +2742,23 @@
"_N$normalSprite": {
"__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952"
},
"_N$pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"_N$hoverSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"hoverSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"_N$disabledSprite": {
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 64
"__id__": 67
}
},
{
@@ -2724,21 +2775,21 @@
"_name": "btn2",
"_objFlags": 0,
"_parent": {
"__id__": 57
"__id__": 60
},
"_children": [
{
"__id__": 71
"__id__": 74
}
],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 73
"__id__": 76
},
{
"__id__": 74
"__id__": 77
}
],
"_prefab": null,
@@ -2783,14 +2834,14 @@
"_name": "Label",
"_objFlags": 0,
"_parent": {
"__id__": 70
"__id__": 73
},
"_children": [],
"_tag": -1,
"_active": true,
"_components": [
{
"__id__": 72
"__id__": 75
}
],
"_prefab": null,
@@ -2835,7 +2886,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 71
"__id__": 74
},
"_enabled": true,
"_useOriginalSize": false,
@@ -2857,7 +2908,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 70
"__id__": 73
},
"_enabled": true,
"_spriteFrame": {
@@ -2883,7 +2934,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 70
"__id__": 73
},
"_enabled": true,
"transition": 2,
@@ -2903,15 +2954,9 @@
},
"duration": 0.1,
"zoomScale": 1.2,
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"hoverSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"clickEvents": [
{
"__id__": 75
"__id__": 78
}
],
"_N$interactable": true,
@@ -2933,11 +2978,23 @@
"_N$normalSprite": {
"__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952"
},
"_N$pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"_N$hoverSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"hoverSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
"_N$disabledSprite": {
"__uuid__": "29158224-f8dd-4661-a796-1ffab537140e"
},
"_N$target": {
"__id__": 70
"__id__": 73
}
},
{
@@ -2954,7 +3011,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 57
"__id__": 60
},
"_enabled": true,
"isAlignOnce": true,
@@ -3003,10 +3060,10 @@
"__id__": 22
},
"vertical": {
"__id__": 39
"__id__": 40
},
"grid": {
"__id__": 56
"__id__": 58
},
"item": {
"__id__": 6

View File

@@ -23,21 +23,24 @@ cc.Class({
this.grid.node.active = false;
var node = this.node.getChildByName(customData);
switch (node.name) {
case 'horizontal': {
this.horizontal.node.active = true;
this.onAddItem(this.horizontal, this.item);
break;
}
case 'vertical': {
this.vertical.node.active = true;
this.onAddItem(this.vertical, this.item);
break;
}
case 'grid': {
this.grid.node.active = true;
this.onAddItem(this.grid, this.item);
break;
}
case 'horizontal':
{
this.horizontal.node.active = true;
this.onAddItem(this.horizontal, this.item);
break;
}
case 'vertical':
{
this.vertical.node.active = true;
this.onAddItem(this.vertical, this.item);
break;
}
case 'grid':
{
this.grid.node.active = true;
this.onAddItem(this.grid, this.item);
break;
}
}
},
@@ -48,8 +51,17 @@ cc.Class({
contentNode.addChild(child);
},
onEventScrollView(event, eventType) {
console.log('eventType=', eventType, cc.ScrollView.EventType);
//当滑动到最后,添加一个
if (cc.ScrollView.EventType.AUTOSCROLL_ENDED_WITH_THRESHOLD == eventType) {
console.log('aa');
this.onAddItem(this.vertical, this.item);
}
},
// called every frame
update: function (dt) {
},
});
});