You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XCode 13.4.1中SwiftUI ColorPicker无法弹出的问题求助

iOS 15.5下SwiftUI ColorPicker无法弹出选择界面的问题

问题详情

在iOS 15.5环境下编写了如下SwiftUI视图代码:

import SwiftUI

struct ContentView: View {
    @State private var bgColor = Color.red

    var body: some View {
            ColorPicker("Set the background color", selection: $bgColor)
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .background(bgColor)
        .padding()
    }
}

点击ColorPicker按钮后,视图仅轻微变暗,预期的颜色选择界面并未弹出,控制台反复出现以下错误:

2022-08-11 23:17:38.322396-0400 PickColors[9817:2995923] [lifecycle] [u 637E7E44-8DD2-4D64-AE35-AB59C96C5CED:m (null)] [com.apple.UIKit.ColorPicker(1.0)] Connection to plugin interrupted while in use.

2022-08-11 23:17:38.324038-0400 PickColors[9817:2995917] [lifecycle] [u 637E7E44-8DD2-4D64-AE35-AB59C96C5CED:m (null)] [com.apple.UIKit.ColorPicker(1.0)] Connection to plugin invalidated while in use.

2022-08-11 23:17:38.874934-0400 PickColors[9817:2995917] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>

2022-08-11 23:17:40.141197-0400 PickColors[9817:2995917] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>

已尝试将ColorPicker放入H/V/Z栈视图、NavigationView中,也执行了清理构建文件夹、重启Xcode等操作,但问题仍未解决。

解决方案

这是iOS 15.5模拟器的已知系统bug,由ColorPicker对应的系统插件连接中断导致,可通过以下方式解决:

  • 使用真实iOS设备测试:真实设备上不会出现该插件崩溃问题,ColorPicker可正常弹出选择界面
  • 升级开发环境:将Xcode和模拟器版本升级到iOS 15.6或更高版本,苹果在后续版本修复了此bug
  • 临时代码适配:调整视图结构,确保ColorPicker的交互优先级高于背景层,示例代码如下:
import SwiftUI

struct ContentView: View {
    @State private var bgColor = Color.red

    var body: some View {
        ZStack {
            // 背景层放在底层,忽略安全区
            bgColor.ignoresSafeArea()
            // ColorPicker放在上层,添加样式确保可点击
            ColorPicker("Set the background color", selection: $bgColor)
                .padding()
                .background(Color.white.opacity(0.8))
                .cornerRadius(8)
        }
    }
}

内容的提问来源于stack exchange,提问作者Torrontés

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 05:33:17