我想提出一个自定义Picker的SegmentedPickerStyle()。我想有相同的行为,但是当我点击内容和其中一个可能选择的边框之间的区域时,onTapGesture它不起作用。当我添加蓝色背景时,它确实有效,但背景清晰时则无效。
使用蓝色背景
无法在清晰的背景下工作
不工作的代码:
import SwiftUI
struct PickerElementView<Content>: View where Content : View {
@Binding var selectedElement: Int
let content: () -> Content
@inlinable init(_ selectedElement: Binding<Int>, @ViewBuilder content: @escaping () -> Content) {
self._selectedElement = selectedElement
self.content = content
}
var body: some View {
GeometryReader { proxy in
self.content()
.fixedSize(horizontal: true, vertical: true)
.frame(minWidth: proxy.size.width, minHeight: proxy.size.height)
// ##################################################################
// CHANGE COLOR HERE TO BLUE TO MAKE IT WORK
// ##################################################################
.background(Color.clear) …Run Code Online (Sandbox Code Playgroud) 在XCode 11 beta 4上,以下内容似乎已被弃用,我不知道该如何重写。有人知道怎么用ForEach(_:id:)吗?
@State private var showTargets = [
(id: 1, state: false, x: 109.28, y: 109.28),
(id: 2, state: false, x: 683, y: 109.28),
(id: 3, state: false, x: 1256.72, y: 109.28)
]
Run Code Online (Sandbox Code Playgroud)
...
var body: some View {
HStack {
ForEach(showTargets.identified(by: \.id)) { item in
Text(String(item.x))
}
}
Run Code Online (Sandbox Code Playgroud) 我已将 a 包裹UITextView在 a 中UIViewRepresentable并包含 a Coordinatoras UITextViewDelegate,但未调用事件。我究竟做错了什么?
struct TextView : UIViewRepresentable {
typealias UIViewType = UITextView
var placeholder : String
@Binding var text: String
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
func makeUIView(context: UIViewRepresentableContext<TextView>) -> UITextView {
let textView = UITextView()
let placeholderLabel = UILabel()
textView.font = UIFont(name: "Helvetica", size: 16)
placeholderLabel.restorationIdentifier = "Placeholder"
placeholderLabel.text = self.placeholder
placeholderLabel.font = UIFont.italicSystemFont(ofSize: (textView.font?.pointSize)!)
placeholderLabel.sizeToFit()
textView.addSubview(placeholderLabel)
placeholderLabel.frame.origin = CGPoint(x: 25, y: (textView.font?.pointSize)! / 2 + 12) …Run Code Online (Sandbox Code Playgroud) 我正在创建一个应用程序,其中登录/注册部分位于模式内部,如果用户未登录,则会显示该模式。
问题是,用户可以通过向下滑动模式来消除该模式...
有可能防止这种情况吗?
var body: some View {
TabView(selection: $selection) {
App()
}.sheet(isPresented: self.$showSheet) { // This needs to be non-dismissible
LoginRegister()
}
}
Run Code Online (Sandbox Code Playgroud)
第二个例子:
我正在使用一种模式来询问信息。除非通过使用“保存”按钮关闭模态,否则用户不能退出该过程。用户必须在按钮起作用之前输入信息。不幸的是,该模式可以通过向下滑动来消除。
有可能防止这种情况吗?
所以我有以下功能。我希望它有一个标准的参数值,但我无法让它工作,因为它需要是一个编译时常量。我知道我可以将它设置为 null 但我希望它是一个特定的功能。
private void func(Func<List<int>, bool> eval = _ => true)
{
var b = eval();
}
Run Code Online (Sandbox Code Playgroud)
甚至有可能做这样的事情吗?