小编ahe*_*eze的帖子

SwiftUI - 如何处理相机权限?

我的 ImagePicker 按预期工作。但是,我正在尝试实现相机权限处理,但我似乎陷入了困境。我收到错误:“函数中缺少返回预期返回 UIImagePickerController”,这是理所当然的。我不确定还能在哪里放置 switch 语句来执行处理。任何帮助表示赞赏。

struct ImagePicker: UIViewControllerRepresentable {
    
    var sourceType: UIImagePickerController.SourceType = .photoLibrary
    
    @Binding var selectedImage: UIImage
    @Binding var alertCameraAccessNeeded: Bool
    @Environment(\.presentationMode) private var presentationMode
    @EnvironmentObject private var userManager: UserManager
    
    let cameraAuthStatus = AVCaptureDevice.authorizationStatus(for: .video)
    
    func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePicker>) -> UIImagePickerController {
        
        switch cameraAuthStatus {
        case .notDetermined: requestCameraPermission()
        case .authorized:
            
            let imagePicker = UIImagePickerController()
            imagePicker.delegate = context.coordinator
            imagePicker.allowsEditing = true
            imagePicker.sourceType = sourceType
            
            return imagePicker
            
        case .restricted, .denied: self.alertCameraAccessNeeded = true
            
        @unknown default:
            fatalError()
        }
        
        
    }
    
    func requestCameraPermission() { …
Run Code Online (Sandbox Code Playgroud)

ios swift swiftui

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

在 Flutter 中实现无限滚动 GridView 的最佳实践?

我想创建一个 GridView 来显示将按偏移量从服务器获取的项目。我在 GridView 中只加载了 10 个项目,当用户滚动到 10 个时,我将加载更多 10 个项目。在 Flutter 中实现无限滚动 GridView 的最佳实践是什么?

flutter

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

SwiftUI - ForEach 删除转换始终仅应用于最后一项

我正在尝试向我的 中添加删除动画ForEach,以便其中的每个Card动画在删除时都会缩放。这是我到目前为止所拥有的:

问题是,无论Card按下哪一个,总是最后一个动画。有时,每张卡片内的文本都有奇怪的滑动/变形动画。这是我的代码:

/// Ran into this problem: "SwiftUI ForEach index out of range error when removing row"
/// `ObservableObject` solution from /sf/answers/4395723531/
class Card: ObservableObject, Identifiable {
    let id = UUID()
    @Published var name: String

    init(name: String) {
        self.name = name
    }
}

struct ContentView: View {
    @State var cards = [
        Card(name: "Apple"),
        Card(name: "Banana "),
        Card(name: "Coupon"),
        Card(name: "Dog"),
        Card(name: "Eat")
    ]
    
    var body: some View {
        ScrollView(.horizontal) { …
Run Code Online (Sandbox Code Playgroud)

swift swiftui swiftui-foreach

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

切换列表中的选择 - SwiftUI

我希望我能清楚地解释我的问题。

我想通过切换从列表中选择一些课程,但无论我尝试过什么,它都不起作用。

我应该做些什么?

感谢您的时间。最好的,穆拉特

struct SubjectCardsView: View {
    // MARK: - Properties
    @State var courses: [Course] = Bundle.main.decode("courses.json")
    
    @State private var toggle: Bool = false
    
    // MARK: - Body
    var body: some View {
        
        NavigationView {
            
            List {
                
                ForEach(courses) { course in
                    Section(header: Text(course.title).font(.system(size: 15, weight: .medium, design: .rounded)).foregroundColor(.blue)) {
                        ForEach(course.courseName, id: \.name) { item  in
                            Toggle(isOn: $toggle, label: {
                                Text(item.name)
                            })
                            
                        }
                    }
                }
            }
            
            .listStyle(InsetGroupedListStyle())
            .navigationBarTitle("Choose your subject", displayMode: .inline).font(.system(size: 16, weight: .medium, design: .rounded))
            .navigationBarItems(leading: Button(action: { …
Run Code Online (Sandbox Code Playgroud)

foreach toggle swift swiftui

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

SwiftUI - 如何从不同视图获取 GeometryReader 大小/高度?

如何从另一个视图访问一个视图的大小?

为了获得“ Hello world! ”文本的高度,我在其上附加了.background()一个GeometryReader。现在,我只是使用 打印高度let _ = print(proxy.size.height)

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello world!")
                .background(
                    GeometryReader { proxy in
                        Color.clear /// placeholder
                        let _ = print(proxy.size.height) /// 20.333333333333332
                    }
                )
            
            Text("Height of first text is ???")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

结果:

“你好世界!”  上面的“第一个文本的高度是???”

我现在想替换为“ Hello world!??? ”的高度。我怎样才能做到这一点?

ios swift swiftui geometryreader

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

NSInvalidArgumentException',原因:'-[NSNull length]:发送到实例的无法识别的选择器

我的 Flutter 应用程序已更新到最新版本的 Flutter,并且我将 firebase_messaging 添加到我的应用程序中。完成此操作后,该应用程序在模拟器上运行良好,但当我尝试在实际 iOS 设备上运行它时崩溃,并出现以下错误:

  -[NSNull length]: unrecognized selector sent to instance 0x1ddcb9ee0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x1ddcb9ee0'
*** First throw call stack:
(0x18c8959d8 0x1a0bfeb54 0x18c7a5bbc 0x18c89801c 0x18c899f8c 0x102deadcc 0x102dec698 0x102deb1a8 0x102dea8bc 0x18c4cd298 0x18c4ce280 0x18c4aa4f0 0x18c4aafdc 0x18c4b4800 0x1d4f3b5a4 0x1d4f3e874)
libc++abi.dylib: terminating with uncaught exception of type NSException
* thread #5, queue = 'com.google.firebase.auth.globalWorkQueue', stop reason = signal SIGABRT
    frame #0: 0x00000001b86f484c libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill: …
Run Code Online (Sandbox Code Playgroud)

ios firebase firebase-authentication flutter firebase-cloud-messaging

0
推荐指数
1
解决办法
2684
查看次数