标签: ios16

如何使用 iOS16 删除 SwiftUI Plain List 中的节标题顶部填充

当我们使用 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)

swiftui swiftui-list ios16 xcode14

21
推荐指数
1
解决办法
5467
查看次数

'init(destination:isActive:label:)' 在 iOS 16.0 中已弃用:在 NavigationStack 或 NavigationSplitView 中使用 NavigationLink(value:label:)

我已经尝试了该网站上发布的示例的不同版本,但没有任何进展。

我也尝试过遵循此处列出的示例:

导航到新的导航类型:

我在这篇文章的标题中收到关于弃用 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)

deprecation-warning swiftui-navigationlink ios16 xcode14

21
推荐指数
1
解决办法
1万
查看次数

iOS 16 CTCarrier 弃用

对于 iOS 16,CTCarrier 似乎已被弃用。

https://developer.apple.com/documentation/coretelephony/ct Carrier

今后接收有关 MCC、MNC 和 ISO 国家/地区代码等运营商信息的正确方法是什么?

在我的公司,我们使用这些信息作为数据点来协助诈骗者检测和其他一些小但相对重要的事情,例如:限制来自我们因定价原因不支持的国家/运营商的电话号码登录。

我找不到任何有关此弃用背后原因的 WWDC 视频,也找不到支持此信息的新类。

ios core-telephony swift ios16

19
推荐指数
1
解决办法
5757
查看次数

如何修复 Xcode 14 警告:呈现值的 NavigationLink 必须出现在基于 NavigationContent 的 NavigationView 内。链接将被禁用

自从安装 Xcode 14 以来,我现在在控制台中打印以下错误消息:

呈现值的 NavigationLink 必须出现在基于 NavigationContent 的 NavigationView 内。链接将被禁用。

我的应用程序的结构如下:

  1. 我将视图 A 包裹在导航视图中。导航视图内部有一个链接到视图 B 的导航链接。

  2. 我的视图 B 没有导航视图,但有一个指向视图 C 的导航链接。视图 B 继承了视图 A 中定义的导航视图

当我按下视图 B 上的后退按钮,弹出回视图 A 时,会打印警告。当我将视图 B 包装在导航视图中时,警告消失,但这当然现在在两个导航视图中显示视图 B,这不是什么我想。

我不确定为什么会打印此警告,因为视图 ​​B 继承了视图 A 中定义的 NavigationView。

swiftui swiftui-navigationlink swiftui-navigationview ios16 xcode14

17
推荐指数
3
解决办法
1万
查看次数

iOS 16 场景方向问题

当我尝试在控制器上仅允许纵向方向时,我总是收到此错误: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)

有人面临同样的问题吗?

portrait orientation ios16 xcode14

15
推荐指数
1
解决办法
2万
查看次数

iOS 16 键盘安全区域未推送更新

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)

重现步骤:

  • 打开键盘
  • 按“点击我”按钮并导航到另一个屏幕
  • 快速返回上一屏幕
  • 键盘被取消了,但是有一个很大的间隙适合键盘尺寸。

还有其他人有类似的问题吗?

keyboard ios swiftui ios16

14
推荐指数
1
解决办法
1885
查看次数

iOS 16 模拟器:在模拟器中运行应用程序会导致“.xpc 错误”

更新到 macOS 13.0 Beta 并安装 Xcode 14.0 Beta 后,我们运行一个应用程序,将目标操作系统设置为 16。出现以下错误:

\n

\n

手动启动时,iPhone 模拟器也不会启动:

\n

在此输入图像描述

\n

这里是描述问题的详细错误消息:

\n
Details\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)

macos xcode ios16 xcode14

12
推荐指数
2
解决办法
1万
查看次数

如何删除所选文本的“搜索网页”选项 iOS 16 xcode14 beta

当选择文本时,我无法删除此勾号,我已经尝试过以下操作:

class CustomUITextField: UITextField {
   open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
      return false
   }
}
Run Code Online (Sandbox Code Playgroud)

它删除了复制、粘贴等内容,但似乎并没有删除这个新的 iOS 16 功能。感谢您的帮助:)

在此输入图像描述

xcode uitextfield swift ios16 xcode14

12
推荐指数
2
解决办法
1534
查看次数

iOS16 Bug 键盘在关闭 SwiftUI 时破坏了布局

在 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

swift swiftui ios16

11
推荐指数
1
解决办法
1657
查看次数

SwiftUI Plain List 如何删除 iOS16 中的顶部标题填充

我正在寻找一种方法来删除 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)

list padding swiftui ios16

10
推荐指数
1
解决办法
2214
查看次数