当我们使用 SwiftUI List 组件并需要一个节标题时,顶部填充将出现在每个节的标题上。
iOS15下,我们用它UITableView.appearance().sectionHeaderTopPadding = 0来解决这个问题。查看附件iOS15&Xcode14构建截图。
但在iOS16中,这个设置似乎不起作用。查看附件iOS16&Xcode14构建截图,滚动时:iOS16&Xcode14构建滚动。
所以,我的问题是如何在iOS16中删除节标题顶部填充,并且当滚动列表时,其节标题将被固定,就像附件iOS15&Xcode14构建滚动一样。
从iOS16开始,SwiftUI List组件似乎使用UICollectionView而不是UITableView,所以我尝试通过全局设置UICollectionView的section top padding来解决这个问题。不幸的是,我没有找到设置 UICollectionView 的部分顶部填充的方法。
我的代码如下。
//
// ContentView.swift
// ListIniOS16
//
// Created by Eric on 2022/07/23.
//
import SwiftUI
struct ContentView: View {
@State private var collections: [ListData] = ListData.collection
init() {
let appBarTheme = UINavigationBarAppearance()
appBarTheme.configureWithOpaqueBackground()
appBarTheme.backgroundColor = UIColor(.gray)
UINavigationBar.appearance().standardAppearance = appBarTheme
UINavigationBar.appearance().scrollEdgeAppearance = appBarTheme
if #available(iOS 15.0, *) {
// can fix sectionHeaderTopPadding issue in iOS15, …Run Code Online (Sandbox Code Playgroud) 我已经尝试了该网站上发布的示例的不同版本,但没有任何进展。
我也尝试过遵循此处列出的示例:
我在这篇文章的标题中收到关于弃用 NavigationLink(destination:isActive) 的警告
struct PhoneLogin: View {
@StateObject var phoneLoginData = PhoneLoginViewModel()
@State var isSmall = UIScreen.main.bounds.height < 750
var body: some View {
VStack {
VStack {
Text("Continue With Phone")
.font(.title2)
.fontWeight(.bold)
.foregroundColor(.black)
.padding()
Image("phone_logo")
.resizable()
.aspectRatio(contentMode: .fit)
.padding()
Text("You'll receive a 4-digit code \n to verify next")
.font(isSmall ? .none : .title2)
.foregroundColor(.gray)
.multilineTextAlignment(.center)
.padding()
// Mobile Number Field . . . . .
HStack {
VStack(alignment: .leading, spacing: 6) {
Text("Enter Your Number")
.font(.caption) …Run Code Online (Sandbox Code Playgroud) 对于 iOS 16,CTCarrier 似乎已被弃用。
https://developer.apple.com/documentation/coretelephony/ct Carrier
今后接收有关 MCC、MNC 和 ISO 国家/地区代码等运营商信息的正确方法是什么?
在我的公司,我们使用这些信息作为数据点来协助诈骗者检测和其他一些小但相对重要的事情,例如:限制来自我们因定价原因不支持的国家/运营商的电话号码登录。
我找不到任何有关此弃用背后原因的 WWDC 视频,也找不到支持此信息的新类。
自从安装 Xcode 14 以来,我现在在控制台中打印以下错误消息:
呈现值的 NavigationLink 必须出现在基于 NavigationContent 的 NavigationView 内。链接将被禁用。
我的应用程序的结构如下:
我将视图 A 包裹在导航视图中。导航视图内部有一个链接到视图 B 的导航链接。
我的视图 B 没有导航视图,但有一个指向视图 C 的导航链接。视图 B 继承了视图 A 中定义的导航视图
当我按下视图 B 上的后退按钮,弹出回视图 A 时,会打印警告。当我将视图 B 包装在导航视图中时,警告消失,但这当然现在在两个导航视图中显示视图 B,这不是什么我想。
我不确定为什么会打印此警告,因为视图 B 继承了视图 A 中定义的 NavigationView。
swiftui swiftui-navigationlink swiftui-navigationview ios16 xcode14
当我尝试在控制器上仅允许纵向方向时,我总是收到此错误:Error Domain=UISceneErrorDomain Code=101“视图控制器不支持所请求的方向。请求:landscapeLeft;支持:纵向”UserInfo={NSLocalizedDescription=视图控制器不支持所请求的方向。请求:景观左;支持:纵向}
我称这个方法为:
func updateOrientation(orientation: UIInterfaceOrientationMask) {
if #available(iOS 16, *) {
DispatchQueue.main.async {
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
self.setNeedsUpdateOfSupportedInterfaceOrientations()
self.navigationController?.setNeedsUpdateOfSupportedInterfaceOrientations()
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientation)) { error in
print(error)
print(windowScene?.effectiveGeometry )
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
有人面临同样的问题吗?
iOS 16 上推送新屏幕时出现奇怪的键盘问题。当您从推送屏幕返回时,键盘安全区域似乎没有更新。
甚至可以在空项目上使用这段代码来重现:
struct ContentView: View {
@State var text = ""
var body: some View {
NavigationView {
VStack {
Spacer()
NavigationLink {
Text("test")
} label: {
Text("Tap me")
}
TextField("", text: $text)
.textFieldStyle(.roundedBorder)
}
.padding()
}
}
}
Run Code Online (Sandbox Code Playgroud)
重现步骤:
还有其他人有类似的问题吗?
更新到 macOS 13.0 Beta 并安装 Xcode 14.0 Beta 后,我们运行一个应用程序,将目标操作系统设置为 16。出现以下错误:
\n\n手动启动时,iPhone 模拟器也不会启动:
\n\n这里是描述问题的详细错误消息:
\nDetails\n\nThe operation couldn\xe2\x80\x99t be completed. xpc error\nDomain: NSPOSIXErrorDomain\nCode: 64\nFailure Reason: xpc error\nUser Info: {\n DVTErrorCreationDateKey = "2022-06-17 16:19:12 +0000";\n IDERunOperationFailingWorker = IDELaunchiPhoneSimulatorLauncher;\n}\n--\n\nAnalytics Event: com.apple.dt.IDERunOperationWorkerFinished : {\n "device_model" = "iPhone14,3";\n "device_osBuild" = "16.0 (20A5283p)";\n "device_platform" = "com.apple.platform.iphonesimulator";\n "launchSession_schemeCommand" = Run;\n "launchSession_state" = 1;\n "launchSession_targetArch" = "x86_64";\n "operation_duration_ms" = 44430;\n "operation_errorCode" = 64;\n "operation_errorDomain" = NSPOSIXErrorDomain;\n "operation_errorWorker" = IDELaunchiPhoneSimulatorLauncher;\n "operation_name" = IDERunOperationWorkerGroup;\n "param_consoleMode" = …Run Code Online (Sandbox Code Playgroud) 当选择文本时,我无法删除此勾号,我已经尝试过以下操作:
class CustomUITextField: UITextField {
open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
return false
}
}
Run Code Online (Sandbox Code Playgroud)
它删除了复制、粘贴等内容,但似乎并没有删除这个新的 iOS 16 功能。感谢您的帮助:)
在 iOS16 中,工作表内部存在键盘的错误,当工作表关闭时键盘消失(没关系),但布局未更新。我只看到了关于同一问题的 1 个问题,想知道也许有人找到了临时解决方法,直到苹果不解决这个问题。重现代码:
struct Test: View {
@State var isPresented: Bool = false
@State var text: String = ""
var body: some View {
VStack{
Button {
isPresented.toggle()
} label: {
Text("PRESENT")
}
}
.sheet(isPresented: $isPresented) {
ZStack {
Color.red
VStack{
TextField("Test", text: $text)
.frame(height: 50, alignment: .center)
Spacer()
Rectangle()
.fill(Color.blue)
.frame(width:300, height: 50)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
视频: https: //vimeo.com/758845068
我正在寻找一种方法来删除 SwiftUI 列表中的顶部填充
借助 iOS 15,我们可以做到UITableView.appearance().sectionHeaderTopPadding = 0
但是,在 iOS 16 中,List 已使用 UICollectionView 重新实现,我找不到删除节标题顶部填充的方法
这是示例代码
import SwiftUI
struct TaskRow: View {
var body: some View {
Text("Task data goes here")
}
}
struct HeaderText: View {
var text:String
var body: some View {
Text(text)
.font(.system(.title3))
.fontWeight(.bold)
.foregroundColor(.primary)
}
}
struct ListWithSections: View {
init() {
if #available(iOS 15.0, *) {
UITableView.appearance().sectionHeaderTopPadding = 0
} else {
// Fallback on earlier versions
}
}
var body: some View { …Run Code Online (Sandbox Code Playgroud) ios16 ×10
xcode14 ×6
swiftui ×5
swift ×3
ios ×2
xcode ×2
keyboard ×1
list ×1
macos ×1
orientation ×1
padding ×1
portrait ×1
swiftui-list ×1
uitextfield ×1