swiftui - 如何使用滑动手势在图像滑块内实现导航链接?
问题描述
浏览这里的帖子以创建图像滑块,我开始考虑如何使用滑动手势实现导航链接,(注意这不是关于滑动手势导航到新视图,而是就像您在图像中滑动一样轻按导航到一个视图。)我一直在实现和试用下面的代码,注意我调用的其余结构是从上面链接中的代码复制的,只是实现不同,我发现通过添加一个导航链接到图像它不再允许滑动手势,我将如何解决这个问题,以便我可以滑动和导航图像?
PS:我考虑过使用滑块解决方案并在那里导航,但填充和 UI 产生了一些奇怪的结果,所以我不同意这个选项。
struct carousel: View {
@State var index = 0
var images = ["Keith Haring Portfolio Photo", "Roy Lichtenstein Portfolio Photo", "Andy Warhol Portfolio Photo", "Jean-Michel Basquiat Portfolio Photo"]
var body: some View {
VStack(spacing: 20) {
PagingView(index: $index.animation(), maxIndex: images.count - 1) {
ForEach(self.images, id: \.self) { imageName in
Image(imageName)
.resizable()
.scaledToFill()
}
}
.aspectRatio(contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 10))
.padding(.horizontal)
}
}
}
解决方案
推荐阅读
- azure - 如何使用 Bicep 在现有 vnet 上创建子网数组?
- python-3.x - matchTemplate (-215:Assertion failed) corr.rows <= img.rows + templ.rows - 1 && corr.cols <= img.cols + templ.cols - 1 in function 'cv::crossCorr'
- ios - 搜索后索引路径行为零
- labview - 检查图像是否已完全加载(没有视觉工具)
- javascript - npx webpack 在不同的模块中寻找 webpack 并抛出错误
- google-bigquery - 如何根据大查询中的特定字符位置在字符串中放置逗号?
- apache-spark - Spark Dataframe 写入 cassandra 表列命令
- c# - 使用具有多条记录的 C# 生成多级 JSON
- html - 使用 iframe 将 Flourish 中的图表嵌入信息丰富的网站是否安全?
- android - 我需要在安卓设备上安装哪些谷歌服务才能让谷歌地图正常工作?