在此代码中,我声明一个图表,其 x 比例域位于两个双精度数之间:
Chart(points, id: \.self) { point in
LineMark(
x: .value("time/s", point.timestamp),
y: .value("potential/mV", point.potential)
)
.foregroundStyle(by: .value("Electrode", point.electrode.symbol))
}
.chartXScale(domain: timeWindow)
// ...
Run Code Online (Sandbox Code Playgroud)
其中timeWindow声明如下:
var timeWindow: ClosedRange<Double> {
doc.contents.time(at: window.lowerBound)...doc.contents.time(at: window.upperBound)
}
Run Code Online (Sandbox Code Playgroud)
并time定义为:
func time(at index: Int) -> Double {
return Double(index) * (1 / sampleRate)
}
Run Code Online (Sandbox Code Playgroud)
然而,生成的图表 x 轴在我提供的下限和上限处没有起点和终点ClosedRange<Double>,而是在图的左侧和右侧有一段神秘空间:
如何使图表遵循我提供的域(边界也显示在底部工具栏工具栏项目组的文本视图中,使用代码Text("\(timeWindow.lowerBound.format()) s to \(timeWindow.upperBound.format()) s"))?如何让 y 轴呈现在图表左侧?
今天将我的 iPhone 更新到 iOS 16.0,从 GitHub 上的已知存储库(即https://github.com/iGhibli/iOS-DeviceSupport )安装了 16.0 的设备支持文件,然后尝试从 Xcode 13.2.1 进行构建,但仍然如此不支持 iOS 16.0。以前,这个技巧适用于 15.5 和 15.6,但现在不适用于 16.0。16.0的文件有问题吗?他们看起来大约3个月大。有没有人见过这个问题并找到解决方案?谢谢!
我在 iOS 16 上遇到问题。VNDetectBarcodesRequest我的代码在 iOS 15 上按预期工作,但在 iOS 16 上它在图像中找不到任何条形码。
我已将代码分离到游乐场,并且在这里遇到了同样的问题。在 Xcode 13.4.1 的 Playground 上运行下面的代码,得到结果:
“Google 链接:可选(“https://www.google.com”)”
在 Xcode 14 上运行相同的代码,我得到了nil结果。在带有 Xcode 14 的 iOS15 模拟器中运行此命令会给出积极的结果,仅在 iOS16 和 Playground 上它不会读取 QR 码。
除此之外,也不会抛出任何异常。
有没有人经历过同样的事情并设法解决这个问题?
这是我的游乐场代码:
import UIKit
import Vision
extension UIImage {
func qrCodeLink(completion: @escaping (String?) -> Void) {
guard let ciImage = CIImage(image: self) else {
completion(nil)
return
}
let imageRequestHandler = VNImageRequestHandler(ciImage: ciImage,
orientation: .up,
options: [:])
let request = VNDetectBarcodesRequest { (request,error) …Run Code Online (Sandbox Code Playgroud) 这个 CSS hack 曾经适用于 iOS 15.6,但在 iOS 16 中不起作用。
@media not all and (min-resolution:.001dpcm) {
@supports (-webkit-appearance:none) {}
}
Run Code Online (Sandbox Code Playgroud)
有没有针对 Safari 16 的新黑客?
因此对于我们的地图,我们使用 MapKit。我们使用 MKPolygons 在地图上方叠加一个图层。此功能自 iOS15 起一直有效,但自 16.1 起,我们收到以下错误,并且应用程序冻结(不会崩溃)。
[VKDefault] Exceeded Metal Buffer threshold of 50000 with a count of 50892 resources, pruning resources now (Time since last prune:6.497636): Assertion with expression - false : Failed in file - /Library/Caches/com.apple.xbs/Sources/VectorKit/src/MDMapEngine.mm line - 1363
Metal API Validation Enabled [PipelineLibrary] Mapping the pipeline data cache failed, errno 22
另一个有趣的日志如下
[IconManager] No config pack found for key SPR London Landmarks知道如何手动清除金属缓存吗?
为了在主屏幕小部件上实现时钟动画。我用
_clockHandRotationEffect(.custom(cycleTime), in:.current, anchor: .center)
Run Code Online (Sandbox Code Playgroud)
有替代品吗?
我正在尝试在我的应用程序中实现密钥。我想知道 ASAuthorizationPublicKeyCredentialAssertion.rawAuthenticatorData 是否支持signCount。看来值总是0。谢谢!
我们如何使用 UIEditMenuInteraction 和 UITextView 来自定义菜单并添加更多按钮?
在 iOS 16 之前我使用的是:
UIMenuController.shared.menuItems = [menuItem1, menuItem2, menuItem3]
Run Code Online (Sandbox Code Playgroud) 从 iOS 16 开始,regionCode尝试regionCode从当前区域设置访问时不再适用。喜欢这个代码
let locale = Locale.current
locale.regionCode
Run Code Online (Sandbox Code Playgroud)
更新到 Xcode 14、iOS 16、Swift 5.7 后,编译项目时我得到:
Sendability of function types in instance method 'addObserver(forName:object:queue:using:)' does not match requirement in protocol 'NotificationCenterProtocol'
Run Code Online (Sandbox Code Playgroud) 我收到日志消息UITextView 正在切换到 TextKit 1 兼容模式,因为它的 textStorage 包含与NSAttributedString使用的TextKit 2 不兼容的属性。documentType: NSAttributedString.DocumentType.html
例子:
func makeUIView(context: Context) -> UITextView {
let textView = UITextView()
return textView
}
func updateUIView(_ uiView: UITextView, context _: Context) {
var currentText: NSAttributedString?
let htmlString = "<html><body><h1>Example</h1></body></html>"
guard let encodedData = htmlString.data(using: .utf8) else {
fatalError("Could not encode HTML data")
}
do {
currentText = try NSAttributedString(data: encodedData,
options: [
.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue
],
documentAttributes: nil)
} catch let error as NSError {
fatalError(error.localizedDescription)
} …Run Code Online (Sandbox Code Playgroud) 我很好奇,有没有一种方法可以控制(或理解) swiftui 在项目之间放置的自动分隔线?
下面是一些显示奇怪行为的代码(在 iOS 模拟器上):
struct FormSeparator: View {
@State private var passwd = ""
var body: some View {
Form {
ZStack(alignment: .trailing) {
TextField("password", text:$passwd)
Text("8 chars min")
.font(.caption)
.foregroundColor(.secondary)
}
TextField("confirm", text:$passwd)
}
}
}
Run Code Online (Sandbox Code Playgroud)
结果如下:
Text这似乎与我堆叠在密码字段顶部的内容有关。如果我将其文本更改为,Image(systemName: "lock")那么一切都会按您的预期进行:
请注意,我什至不明白为什么在这种情况下它没有一直延伸到整个表单。大概这是故意的,有人见过关于这种情况的官方信息吗?我们知道如何控制它吗?
我有一个这样的模型...
struct User: Codable {
let followersCount: Int
let followingCount: Int
}
Run Code Online (Sandbox Code Playgroud)
使用 NavigationStack 我希望能够使用基于 Value 的 NavigationLink
NavigationLink(value: user.followersCount) {
Text("Followers")
}
NavigationLink(value: user.followingCount) {
Text("Following")
}
.navigationDestination(for: Int.self) { _ in
FollowersView()
}
.navigationDestination(for: Int.self) { _ in
FollowingView()
}
Run Code Online (Sandbox Code Playgroud)
因为这两个值都是 Int。有没有办法区分两者?
swiftui swiftui-navigationlink ios16 swiftui-navigationstack