SwiftUI无法使用HStack的Spacer [英] SwiftUI can't tap in Spacer of HStack

查看:55
本文介绍了SwiftUI无法使用HStack的Spacer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图,列表的每一行包含一个带有某些文本视图和图像的HStack,如下所示:

I've got a List view and each row of the list contains an HStack with some text view('s) and an image, like so:

HStack{
    Text(group.name)
    Spacer()
    if (groupModel.required) { Text("Required").color(Color.gray) }
    Image("ic_collapse").renderingMode(.template).rotationEffect(Angle(degrees: 90)).foregroundColor(Color.gray)
}.tapAction { self.groupSelected(self.group) }

这似乎很好用,除了当我在文本和图像之间的空白区域(Spacer()所在的位置)点击时,tap动作未注册.仅当我在文本或图像上点击时,点击动作才会发生.

This seems to work great, except when I tap in the empty section between my text and the image (where the Spacer() is) the tap action is not registered. The tap action will only occur when I tap on the text or on the image.

还有其他人遇到此问题/知道解决方法吗?

Has anyone else faced this issue / knows a workaround?

推荐答案

据我最近了解,还有:

HStack {
  ...
}
.contentShape(Rectangle())
.onTapGesture { ... }

对我来说很好.

这篇关于SwiftUI无法使用HStack的Spacer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆