我正在 SwiftUI 中制作一个带有侧边栏的应用程序,该侧边栏将显示分层信息。在本例中,我显示一个项目列表,每个项目内部都会有一些待办事项列表。
正如您在上面看到的,我的问题是,当应用程序启动时,所有部分都默认展开,我希望它们默认折叠。我使用ListwithSection(header:content:)作为侧边栏,每个部分内都有一个OutlineGroup.
这是我使用的代码
// Data source for the list
class MyEnvironmentObject: ObservableObject {
@Published var listItems = [
ListItem(name: "Project 1", children: [
ListItem(name: "List 1")
]),
ListItem(name: "Project 2", children: [
ListItem(name: "List 1"),
ListItem(name: "List 2")
]),
ListItem(name: "Project 3", children: [
ListItem(name: "Example list")
])
]
}
struct ContentView: View {
@EnvironmentObject var dataSource: MyEnvironmentObject
func listItem(for item: ListItem) -> some View {
Text(item.name)
}
var …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中有一个显示矩形卡片列表的布局 - 每个卡片都应该可以点击(一次)以显示一组操作按钮和更多信息等。
我已经实现了这一点,.onTapGesture()并且我还.contentShape(Rectangle()强制执行了可点击区域。然而,虽然我的实现适用于触摸屏界面,但当我将它与 iPadOS 鼠标支持一起使用时,以及在 Catalyst 上,我看到了一些非常意外的行为。
我在下面制作了一个最小的可重现示例,您可以复制该示例以重现问题。
使用鼠标/触控板输入时出现的问题:
如果您正在运行示例代码,您应该能够通过反复移动鼠标并尝试单击来查看问题。除非您在同一位置多次单击,否则它不起作用。
什么按预期工作:
我用来重现这个问题的代码(每次记录点击手势时都有一个计数器来计数):
struct WidgetCompactTaskItemView: View {
let title: String
let description: String
var body: some View {
HStack {
Rectangle()
.fill(Color.purple)
.frame(maxWidth: 14, maxHeight: .infinity)
VStack(alignment: .leading) {
Text(title).font(.system(size: 14, weight: .bold, design: .rounded))
Text(description).font(.system(.footnote, design: .rounded))
.frame(maxHeight: .infinity)
.fixedSize(horizontal: false, vertical: true)
.lineLimit(1)
.padding(.vertical, …Run Code Online (Sandbox Code Playgroud) 我正在为我的应用中的UI元素编写动画代码.应用程序工作正常,直到我在某些UI元素上更改了alpha,当我收到此错误时:
libc++abi.dylib: terminating with uncaught exception of type NSException
Run Code Online (Sandbox Code Playgroud)
没有堆栈跟踪或指示错误可能在输出中的位置,只是指向AppDelegate类的Signal SIGABRT.
该应用程序在上一个版本中工作,之后我更改了alpha设置,我将其解除尝试并调试情况.我已经尝试禁用我最近修改的代码的某些部分,例如Game Center,我尝试设置断点但无法使应用程序正常工作.
我的问题 - 这是什么错误,它来自哪里?
以下是我最近修改过的一些代码,如果你需要看到它:
//This code is called in a Game Center Authentication method
UIView.animate(withDuration: 0.5, animations: {
self.pointsIndicator.center.x += self.view.bounds.width
// self.pointsIndicator.alpha = 1
})
UIView.animate(withDuration: 0.5, delay: 0.3, options: [], animations: {
self.pointsLabel.center.x += self.view.bounds.width
// self.pointsLabel.alpha = 1
}, completion: nil)
Run Code Online (Sandbox Code Playgroud)
查看将出现:
override func viewWillAppear(_ animated: Bool) {
//Setup animations
print("\(progBar.center.x) Before")
pointsIndicator.center.x -= view.bounds.width
pointsLabel.center.x -= view.bounds.width
progBar.center.x -= view.bounds.width
masterLabel.center.x -= view.bounds.width …Run Code Online (Sandbox Code Playgroud) 我正在为 iOS 14 制作一个 SwiftUI 应用程序,我有一个侧边栏列表,它使用 list 的新children:属性使列表可扩展:
但是,目前我只能在我精确单击披露箭头时展开此列表。例如,当我单击“我的酷项目”文本时,我也希望能够展开此列表。
这在“文件”应用程序中是可能的 - 当我单击“位置”文本时,我可以看到“位置”项的所有子项,但我不知道如何在我的应用程序中执行此操作。
为了澄清,List每个项目的项目是一个Text视图,子列表项目是NavigationLink
这种行为在 SwiftUI 中是否可能,甚至通过 onTapGesture 或除 a 以外的其他东西以编程方式进行List?提前感谢您的任何帮助/建议!
我正在尝试让 iCloud 在 iPhone 和 Apple Watch 之间工作(在 watchOS 3 上使用 CloudKit)。我已将 Watch Extension 中的云容器指定为与 iOS 目标中的云容器相同,但是在运行该应用程序时,我从我所做的查询中收到此错误:
Failure retrieving: Optional(<CKError 0x17d45cf0: "Unknown Item" (11/2003); server message = "did not find record type recordTypeId="Recommendation""; uuid = 37D53C78-FF19-4CE3-80BD-C1990F0135A2; container ID = "iCloud.mathsrobot.MathsRobot-LearnMaths.watchkitapp.watchkitextension">)
Run Code Online (Sandbox Code Playgroud)
从容器 ID,我可以看出它没有使用 iOS 应用程序容器,应该是iCloud.mathsrobot.MathsRobot-LearnMaths. 如何让它为 iOS 应用程序使用 iCloud 容器?
iOS 目标能力截图 iCloud 的主要 iOS 目标能力
观看目标功能截图 使用 iCloud 观看扩展目标功能