future 1 год назад
Родитель
Сommit
392da57cc9

+ 1 - 1
assets/script/ui/car_lib/car_lib_bottom.ts

@@ -51,7 +51,7 @@ export class car_lib_bottom extends base_ui {
         for (let index = 0; index < this.num_total_count; index++) {
             let page = instantiate(this.pageView_page_item)
             let data_list = tools.all_car_page_list[index]
-            page.getComponent(car_lib_page_item).init(index,data_list, this.onSelectedItem.bind(this), this.onClickListItem.bind(this))
+            page.getComponent(car_lib_page_item).init(this.pageView, index,data_list, this.onSelectedItem.bind(this), this.onClickListItem.bind(this))
             this.pageView.getComponent(PageView).addPage(page)
         }
     }

+ 55 - 2
assets/script/ui/car_lib/car_lib_page_item.ts

@@ -1,4 +1,4 @@
-import { _decorator, Component, instantiate, Layout, Node, Prefab, UITransform } from 'cc';
+import { _decorator, Component, EventTouch, instantiate, Layout, Node, PageView, Prefab, UITransform, Vec2 } from 'cc';
 import { car_item_data } from '../../data';
 import { userDataManager } from '../../manager/userDataManager';
 import { car_lib_list_item } from './car_lib_list_item';
@@ -9,10 +9,17 @@ export class car_lib_page_item extends Component {
     @property(Node) list:Node = null
     @property(Node) list_content:Node = null
     @property(Prefab) list_item:Prefab = null
+    private m_pageView:Node = null
     private m_index = -1
     private m_data_list:car_item_data[] = []
     private m_click_cb = null
 
+    private chuandi:boolean = true
+    private startPosition:Vec2 = new Vec2(0,0)
+    private movePosition:Vec2 = new Vec2(0,0)
+    private endPosition:Vec2 = new Vec2(0,0)
+    private pageIdx = 0
+
     protected start(): void {
         let list_content_size = this.list_content.getComponent(UITransform).contentSize
         let item_contenteSize = instantiate(this.list_item).getComponent(UITransform).contentSize
@@ -22,9 +29,55 @@ export class car_lib_page_item extends Component {
             this.list_content.getComponent(Layout).paddingRight = horizontal_padding
             this.list_content.getComponent(Layout).spacingX = horizontal_padding
         }
+        this.list.on(Node.EventType.TOUCH_START, this.touchStart, this)
+        this.list.on(Node.EventType.TOUCH_MOVE, this.touchMove, this)
+        this.list.on(Node.EventType.TOUCH_END, this.touchEnd, this)
+        this.list.on(Node.EventType.TOUCH_CANCEL, this.touchEnd, this)
+    }
+
+    public touchStart(event:EventTouch) {
+        this.chuandi = true
+        this.startPosition = event.getLocation()
+        this.pageIdx = this.m_pageView.getComponent(PageView).getCurrentPageIndex()
+    }
+
+    private touchMove(event:EventTouch) {
+        // console.log('touchMove=',event)
+        if(this.chuandi == false) {
+            return
+        }
+        this.chuandi = true
+        this.movePosition = event.getLocation();
+        let distance_x = this.movePosition.x - this.startPosition.x;
+        let distance_y = this.movePosition.y - this.startPosition.y;
+        // console.log("距离差== ", distance_x, distance_y);
+        //判断是否需要翻页
+        if (Math.abs(distance_x) > 50 && distance_x > 0) {
+            // console.log("向前翻页");
+            this.m_pageView.getComponent(PageView).scrollToPage(this.pageIdx - 1);
+            this.chuandi = false;
+        } else if (Math.abs(distance_x) > 50 && distance_x < 0) {
+            // console.log("向后翻页");
+            this.m_pageView.getComponent(PageView).scrollToPage(this.pageIdx + 1);
+            this.chuandi = false;
+        }
+    }
+
+    private touchEnd(event:EventTouch) {
+        // console.log('touchEnd=',event)
+        this.endPosition = event.getLocation();
+        let distance_x = this.endPosition.x - this.startPosition.x;
+        let distance_y = this.endPosition.y - this.startPosition.y;
+        //判断是否是点击
+        if (Math.abs(distance_y) < 50 && Math.abs(distance_x) < 50) {
+        //   console.log("触摸结束,是点击");
+        } else {
+        //   console.log("结束1");
+        }
     }
 
-    init(index, data_list:car_item_data[], selected_cb, click_cb) {
+    init(pageView, index, data_list:car_item_data[], selected_cb, click_cb) {
+        this.m_pageView = pageView
         this.m_index = index
         this.m_data_list = data_list
         this.m_click_cb = click_cb