瀏覽代碼

界面优化
TableView.ts item不足界面宽度时 居中

kaka 4 年之前
父節點
當前提交
e97252702f

文件差異過大導致無法顯示
+ 251 - 163
assets/resources/game/prefab/uiPanel/HarvestPanel.prefab


+ 2 - 2
assets/resources/game/texture/public/windowBg.png.meta

@@ -26,8 +26,8 @@
       "height": 603,
       "rawWidth": 609,
       "rawHeight": 614,
-      "borderTop": 0,
-      "borderBottom": 0,
+      "borderTop": 295.5,
+      "borderBottom": 289.5,
       "borderLeft": 0,
       "borderRight": 0,
       "subMetas": {}

+ 23 - 2
assets/script/game/component/TableView.ts

@@ -135,6 +135,13 @@ export default class TableView extends cc.Component {
         if (this.isHideAllChild) this.isHideAllChild = false;
         this.scrollView.node.on('scrolling', this.callback, this);
         // cc.log('tableView结束:' + this.testTime());
+
+        //水平居中
+        if (this.direction == Direction.horizontal) {
+            if (this.content.width < this.layerWith) {
+                this.node.x = (this.layerWith - this.content.width) * 0.5;
+            }
+        }
     }
 
     /**
@@ -324,7 +331,14 @@ export default class TableView extends cc.Component {
      * @param num  
      */
     private updateContentHeigh(num: number) {
-        this.content.height = num > this.layerHeight ? num : this.layerHeight;
+        // this.content.height = num > this.layerHeight ? num : this.layerHeight;
+        this.content.height = num;
+        if (this.content.height <= this.layerHeight) {
+            this.scrollView.vertical = false;
+        }
+        else {
+            this.scrollView.vertical = true;
+        }
         // cc.log('滚动条高度:', this.content.height);
     }
 
@@ -333,7 +347,14 @@ export default class TableView extends cc.Component {
      * @param num  
      */
     private updateContentWidth(num: number) {
-        this.content.width = num > this.layerWith ? num : this.layerWith;
+        // this.content.width = num > this.layerWith ? num : this.layerWith;
+        this.content.width = num;
+        if (this.content.width <= this.layerWith) {
+            this.scrollView.horizontal = false;
+        }
+        else {
+            this.scrollView.horizontal = true;
+        }
         // cc.log('滚动条高度:', this.content.height);
     }
 

部分文件因文件數量過多而無法顯示