我為應用程式內部的指令寫了一個擴展,寫了一個錯誤后:
Type '() -> ()' cannot conform to 'ShapeStyle'
這是擴展本身,這是錯誤:
extension View{
//MARK: - Custom Spotlight Modefier
func spotlight(enabled: Bool, title: String = "")->some View{
return self //Error Message: Type '() -> ()' cannot conform to 'ShapeStyle'
.overlay{
if enabled{
//To Get the Current Content Size
GeometryReader{proxy in
let rect = proxy.frame(in: .global)
SpotlightView(rect: rect, content: title){
self
}
}
}
}
}
//MARK: - Screen Bounds
func screenBound()->CGRect{ }
//MARK: - Root Controller
func rootController()->UIViewController{ }
}
顯示指令所需的結構
struct SpotlightView<Content: View>: View{
var content: Content
var title: String
var rect: CGRect
init(rect: CGRect ,title: String, @ViewBuilder content: @escaping ()->Content){
self.content = content()
self.title = title
self.rect = rect
}
@State var tag: Int = 1009
var body: some View{
Rectangle()
.fill(.white.opacity(0.02))
.onAppear {
addOverlayView()
}
.onDisappear{
removeOverlayView()
}
}
//MARK: - Removing the overlay when over view disappeared
func removeOverlayView(){ }
//MARK: - Adding An Extra View over the Current View
func addOverlayView(){ }
@ViewBuilder
func overlaySwiftUIView()->some View{ }
//MARK: - Random Number for Tag
func generateRandom()->Int{ }
uj5u.com熱心網友回復:
在您對 的擴展中View,在這一行中,SpotlightView(rect: rect, content: title)您與初始化程式不匹配。需要3個SpotlightView引數:
- rect,型別為 CGRect
- 標題,字串型別
- 內容,閉包
您提供:
- rect,型別為 CGRect
- 內容,字串型別
- 關閉
首先更正對 的呼叫SpotlightView,將“內容”替換為“標題”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/431349.html
上一篇:Swift在十進制格式中失去精度
下一篇:firestore獲取子集合
