```
ScrollView(.horizontal,showsIndicators: false) {
? ? ? ? ? ? ? ? HStack(spacing:8){
? ? ? ? ? ? ? ? ? ? ForEach(0..
? ? ? ? ? ? ? ? ? ? ? ? Button(action: {
? ? ? ? ? ? ? ? ? ? ? ? },label: {
? ? ? ? ? ? ? ? ? ? ? ? ? ? Text("Button")
? ? ? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
```
該代碼展示了一個滑動視圖,并且根據(jù)數(shù)據(jù)源titles遍歷創(chuàng)建了Button控件斗幼,但是查看圖層ScrollerView容器寬高均正常
但是無法響應點擊事件,按照UIKit排查覺得應該是俯視圖沒有高度的問題,但是圖層顯示父視圖高度正常衣盾,確無法點擊事件舰罚。修改代碼如下:
```
ScrollView(.horizontal,showsIndicators: false) {
? ? ? ? ? ? ? ? HStack(spacing:8){
? ? ? ? ? ? ? ? ? ? ForEach(0..
? ? ? ? ? ? ? ? ? ? ? ? Button(action: {
? ? ? ? ? ? ? ? ? ? ? ? },label: {
? ? ? ? ? ? ? ? ? ? ? ? ? ? Text("Button")
? ? ? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? .padding(.top,22)
? ? ? ? ? ? ? ? .padding(.bottom,22)
? ? ? ? ? ? ? ? .padding(.leading,12)
? ? ? ? ? ? ? ? .padding(.trailing,12)
? ? ? ? ? ? }
```
增加內(nèi)邊距,在度撐開ScrollerView容器高度玷室,發(fā)現(xiàn)Button可以響應事件。
分析如下:
1. 自適應的Button容器,再布局容器里不給內(nèi)邊距丈积,會造成實際ScrollerView 承載視圖高度不足以接收點擊事件
2.為何會發(fā)生圖層高度均正常,產(chǎn)生無法接收點擊事件的問題债鸡,應該是內(nèi)部繪制判斷問題