小编Mat*_*199的帖子

Swift:异步加载和显示照片

我正在努力解决从iPhone到iPhone显示图片库的问题collectionView

如果某人在画廊内有50张照片,则一切正常。问题是,当某人有数千张照片时,图库会加载10秒钟,这对我的应用程序不利。
当我从Facebook加载图像时,会发生相同的问题。该应用程序正在等待下载所有照片,然后显示出来。我想在加载过程中一张一张地显示图像,而不是等待它全部加载。

我知道我应该使用DispachQueue并且确实使用过,但是有一些我看不到的错误。
这是我用来从iPhone图库中获取图像的代码:

func grapPhotos() {
    let imgManager = PHImageManager.default()
    let requestOptions = PHImageRequestOptions()
    requestOptions.isSynchronous = true
    requestOptions.deliveryMode = .highQualityFormat
    let fetchOptions = PHFetchOptions()

    fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]

    if let fetchResulat : PHFetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions) {

        if fetchResulat.count > 0 {

            for i in 0..<fetchResulat.count {

                imgManager.requestImage(for: fetchResulat.object(at: i), targetSize: CGSize(width: 200, height:200), contentMode: PHImageContentMode.aspectFill, options: requestOptions, resultHandler: {
                    (image, eror) in

                    self.imageArray.append(image!)

                    DispatchQueue.main.async {
                        self.collectionView.reloadData()
                    }
                })
            } …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview swift

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

按钮和一些用户交互对 iOS14 应用程序没有响应

我正在为我的 iOS 应用程序的一个奇怪的错误而苦苦挣扎。在 iOS 13 应用程序中使用模拟器时,它可以正常工作,但在使用 iOS 14 按钮时,开关和其他功能没有响应。控制台没有错误输出。我不明白为什么只有 XCode 11 和 iOS 14 才会发生这种情况。

这是一个片段,在View.

 let logButton: UIButton = {
    let button = UIButton()
    button.translatesAutoresizingMaskIntoConstraints = false
    button.setLogInButton()
    button.setTitle(NSLocalizedString("log_in", comment: ""), for: .normal)
    return button
}()
Run Code Online (Sandbox Code Playgroud)

在这里,我将目标分配给按钮。

   override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initConstraints()
        backgroundColor = UIColor().settingsTableViewCellColor()
        logButton.addTarget(self, action: #selector(buttonLogInLogOut), for: .touchUpInside)
    }
Run Code Online (Sandbox Code Playgroud)

有行动

@objc func buttonLogInLogOut(_ sender: UIButton){
    print("Log in clicked")
    delegate?.logInLogOutFunc(sender)
}
Run Code Online (Sandbox Code Playgroud)

正如我所说,按钮(开关和其他按钮)仅在 iOS 14 中没有响应。看起来targetActions不起作用。

感谢您提供任何帮助。问候马特

html xcode ios swift xcode11

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

标签 统计

ios ×2

swift ×2

html ×1

uicollectionview ×1

xcode ×1

xcode11 ×1