Open ZWP233 opened 2 years ago
在后台线程中改变UI布局
DispatchQueue.global().async { let asset: Any let mediaType: PHAssetMediaType let photoAsset: PhotoAsset switch result { case .image(let image): asset = image mediaType = .image photoAsset = .init(localImageAsset: .init(image: image)) case .video(let videoURL): asset = videoURL mediaType = .video photoAsset = .init(localVideoAsset: .init(videoURL: videoURL)) } var canSelect = false if !picker.canSelectAsset(for: photoAsset, showHUD: true) { if !didDismiss { DispatchQueue.main.sync { cameraController.dismiss(animated: true) } } canSelect = true } if self.config.saveSystemAlbum { self.saveSystemAlbum( for: asset, mediaType: mediaType, location: location ) { [weak self] in self?.cameraControllerDismiss(canSelect) } return } self.addedCameraPhotoAsset( photoAsset ) { [weak self] in self?.cameraControllerDismiss(canSelect) } }
在主线程更新UI
DispatchQueue.main.async { //* 更新操作写这里 }
在后台线程中改变UI布局
DispatchQueue.global().async { let asset: Any let mediaType: PHAssetMediaType let photoAsset: PhotoAsset switch result { case .image(let image): asset = image mediaType = .image photoAsset = .init(localImageAsset: .init(image: image)) case .video(let videoURL): asset = videoURL mediaType = .video photoAsset = .init(localVideoAsset: .init(videoURL: videoURL)) } var canSelect = false if !picker.canSelectAsset(for: photoAsset, showHUD: true) { if !didDismiss { DispatchQueue.main.sync { cameraController.dismiss(animated: true) } } canSelect = true } if self.config.saveSystemAlbum { self.saveSystemAlbum( for: asset, mediaType: mediaType, location: location ) { [weak self] in self?.cameraControllerDismiss(canSelect) } return } self.addedCameraPhotoAsset( photoAsset ) { [weak self] in self?.cameraControllerDismiss(canSelect) } }