UIDevice.current.name 如果使用 iOS15,它可以工作,但是当我在 iOS16(beta3)上测试时,仍然始终返回“iPad”名称。
查看相关 WWDC 2022 视频文件
我用了:
有谁知道为什么自 iOS 16 beta 以来 SwiftUI 中菜单的主要操作不起作用?
Menu {
Button {
print("action 1")
} label: {
Text("Action 1")
}
} label: {
Text("Menu")
} primaryAction: {
print("primary")
}
Run Code Online (Sandbox Code Playgroud) 我正在开发我的 SwiftUI 项目,并为快捷方式应用程序添加了一些 AppIntents。目前我无法本地化标题和描述。标题和描述的类型为 LocalizedStringResource(iOS16+ 提供)。
我尝试将以下代码本地化为德语,但我不知道该怎么做。
struct Add_Memory_Shortcut: AppIntent {
// The name of the action in Shortcuts
// TODO: Localization
static var title : LocalizedStringResource = "Create Memory"
// Description of the action in Shortcuts
// Category name allows you to group actions - shown when tapping on an app in the Shortcuts library
static var description: IntentDescription = IntentDescription("Create a new memory", categoryName: "Creating")
}
Run Code Online (Sandbox Code Playgroud)
任何帮助或链接表示赞赏。谢谢 :)
我的应用程序是用 SwiftUI 构建的,除了一些我目前正在修复的设计怪癖之外,大部分都可以像 iOS 16 一样运行。
怪癖之一是列表的背景颜色。以前我曾使用 Introspect 设置列表背景的颜色,但由于列表已在 iOS16 中重新实现,因此该方法不再有效。
我已经通过使用新的scrollContentBackground修饰符为iOS 16设备解决了这个问题:
List() {
some foreach logic here
}
.background(color)
.scrollContentBackground(.hidden)
Run Code Online (Sandbox Code Playgroud)
除了一个问题之外,这按预期工作。
当列表为空时,背景颜色将被忽略,它根据浅色或深色模式设置显示白色或黑色背景(甚至不包括分组的背景颜色)。
有其他人遇到过这个问题吗(或者我做错了什么?),如果是的话,你想出了什么解决方案?
谢谢,C
即使代码更改不直接触及意图,从新框架中提取应用程序意图也AppIntents需要花费大量时间。
在构建日志中,发生此步骤的原因有所不同,但主要是“文件 X 已更改”,我想知道是否可以以某种方式缓存该意图或至少仅在生产构建中提取此元数据?Simple#if debug不会阻止执行此步骤。
我正在尝试使用 Xcode 向 App Store 提交本机应用程序。该应用程序是使用适用于 iOS 16 的 Firebase 和 SwiftUI 构建的。提交结束时出现以下警告:
应用程序引用 Payload/MyApp.app/MyApp 中的非公共选择器:defineAppInstallationAttributionWithCompletionHandler:、lookupAdConversionDetails:、transform:
我没有使用此 API 在代码中执行任何操作。有谁知道如何解决这一问题?
谢谢!
我在 iOS 16 上发现了一个奇怪的自动旋转问题,这在其他 iOS 版本中没有出现过。更糟糕的是,如果我将设备连接到 XCode 并进行调试,则不会出现该问题。仅当我通过触摸应用程序图标直接在设备上启动应用程序时才能看到它,这就是我无法识别任何修复的原因。我所做的是在应用程序启动时禁用自动旋转(通过仅返回 .landscape supportedInterfaceOrientations),然后在 0.2 秒后不久,我强制自动旋转到设备的当前界面方向(使用self.setNeedsUpdateOfSupportedInterfaceOrientations)。但是,如果通过触摸应用程序图标直接启动应用程序(而不是从调试器启动),则自动旋转会失败!
这是完整重现该问题的示例代码。运行应用程序时,请确保 iPhone 处于纵向模式。该函数viewWillTransition(to size:, with coordinator:)不会被调用,并且所有子视图不会自动旋转。请建议我一个解决方法!
import UIKit
class ViewController: UIViewController {
public var windowOrientation: UIInterfaceOrientation {
return view.window?.windowScene?.interfaceOrientation ?? .unknown
}
private var disableAutoRotation = true
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
var orientations:UIInterfaceOrientationMask = .landscapeRight
if !self.disableAutoRotation {
orientations = .all
}
return orientations
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColor.systemGreen …Run Code Online (Sandbox Code Playgroud) 是否可以使用 Apple 的新 SwiftUI 图表框架创建饼图/圆环图?
WWDC 视频中显示了饼图图像。任何有关如何创建饼图的帮助或代码示例将不胜感激。
这是示例项目源代码:示例代码
import SwiftUI
struct TestMenuInSafeAreaInset: View {
@State private var message = ""
var body: some View {
VStack {
Rectangle()
.fill(Color.blue)
}
.safeAreaInset(edge: .bottom) {
HStack {
TextField("Input your message", text: $message)
.padding()
.background(Color.brown)
.cornerRadius(12)
.foregroundColor(.white)
Menu {
Button {
} label: {
Text("Confirm")
}
Button {
} label: {
Text("Cancel")
}
} label: {
Image(systemName: "square.and.arrow.up.fill")
.tint(.white)
.padding()
.background(Color.brown)
.cornerRadius(50)
}
}
.padding()
}
}
}
struct TestMenuInSafeAreaInset_Previews: PreviewProvider {
static var previews: some View {
TestMenuInSafeAreaInset() …Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用视图控制器的应用程序,并且正在慢慢迁移到使用使用 SwiftUI 构建的视图。
我正在开发新的 swiftUI 视图,因此我将 UIHostingController 设置为 SceneDelegate 中的 rootViewController
总的来说,我的整个应用程序仅限于此处的纵向
我希望允许在左侧纵向和横向显示一些个人视图
这是我到目前为止所使用的 swiftUI,它在 iOS 15 中完美运行
在 AppDelegate 我有
static var orientationLock = UIInterfaceOrientationMask.portrait
Run Code Online (Sandbox Code Playgroud)
然后在方法中
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask
Run Code Online (Sandbox Code Playgroud)
这设置为返回
return AppDelegate.orientationLock
Run Code Online (Sandbox Code Playgroud)
然后在特定的 swiftUI 文件中我想要允许旋转,我只需通过将此修改器添加到主视图来处理屏幕旋转
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
if orientation.isLandscape {
AppDelegate.orientationLock = UIInterfaceOrientationMask.landscapeLeft
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
UINavigationController.attemptRotationToDeviceOrientation()
} else {
AppDelegate.orientationLock = UIInterfaceOrientationMask.portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
UINavigationController.attemptRotationToDeviceOrientation()
}
}
.onDisappear {
DispatchQueue.main.async {
AppDelegate.orientationLock = UIInterfaceOrientationMask.portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
UINavigationController.attemptRotationToDeviceOrientation() …Run Code Online (Sandbox Code Playgroud) ios16 ×10
swiftui ×7
ios ×6
swift ×5
appintents ×2
xcode ×2
firebase ×1
localization ×1
safearea ×1
swiftui-list ×1
uikit ×1
wwdc ×1
xcode14 ×1
xcodebuild ×1