我目前正在尝试在图像顶部绘制 Firebase ML Kit 识别的文本框。目前,我还没有成功,我根本看不到任何框,因为它们都显示在屏幕外。我正在查看这篇文章以供参考:https://medium.com/swlh/how-to-draw-bounding-boxes-with-swiftui-d93d1414eb00以及该项目: https: //github.com/firebase /quickstart-ios/blob/master/mlvision/MLVisionExample/ViewController.swift
这是应显示框的视图:
struct ImageScanned: View {
var image: UIImage
@Binding var rectangles: [CGRect]
@State var viewSize: CGSize = .zero
var body: some View {
// TODO: fix scaling
ZStack {
Image(uiImage: image)
.resizable()
.scaledToFit()
.overlay(
GeometryReader { geometry in
ZStack {
ForEach(self.transformRectangles(geometry: geometry)) { rect in
Rectangle()
.path(in: CGRect(
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height))
.stroke(Color.red, lineWidth: 2.0)
}
}
}
)
}
}
private func transformRectangles(geometry: GeometryProxy) -> …Run Code Online (Sandbox Code Playgroud) 我想在 SwiftUI 中创建一个我想在整个应用程序中重复使用的自定义按钮。该按钮基本上只是一个没有标签的可点击图像。我想为它创建一个自定义的 ButtonStyle 。但是,我在遵守 ButtonStyle 协议时遇到了问题,因为不知道我应该在这里选择哪种类型。
我已经尝试过some View或只是View为了<#type>但没有成功。
struct customButtonStyle: ButtonStyle {
typealias Body = <#type>
}
Run Code Online (Sandbox Code Playgroud)
该错误消息我在尝试时使用View或者some View是:
Type 'customButtonStyle' does not conform to protocol 'ButtonStyle'和XCode的只是增加了这条线typealias Body = <#type>一次。
非常感谢您的帮助。