Code Monkey home page Code Monkey logo

Comments (6)

SilenceLove avatar SilenceLove commented on August 15, 2024

/// 获取相机胶卷相册的 `PhotoAssetCollection` 对象
/// 打开选择器默认显示的相册
static func fetchCameraAssetCollection(
_ config: PickerConfiguration,
options: PHFetchOptions
) -> PhotoAssetCollection?

config.fetchAssetCollection = TestPhotoFetchAssetCollection.self

public struct TestPhotoFetchAssetCollection: PhotoFetchAssetCollection {
    public static func fetchCameraAssetCollection(_ config: PickerConfiguration, options: PHFetchOptions) -> PhotoAssetCollection? {
        if /*自定义默认显示的相册*/ {
            if config.creationDate {
                options.sortDescriptors = [
                    NSSortDescriptor(
                        key: "creationDate",
                        ascending: config.creationDate
                    )
                ]
            }
            var collection: PhotoAssetCollection?
            fetchAssetCollections(options: options) { assetCollection, isCameraRoll, stop in
                if !isCameraRoll {
                    collection = assetCollection
                    stop.pointee = true
                }
            }
            if let collection {
                return collection
            }
        }
        return DefaultPhotoFetchAssetCollection.fetchCameraAssetCollection(config, options: options)
    }
}

from hxphotopicker.

liumengdi666 avatar liumengdi666 commented on August 15, 2024

你好, 按照上边的方式实现了, 我们采用albumShowMode方式为popup,有点小问题, 比如自定义相册为'xxx', 弹出后点击上边的标题展示albumList会发现显示的是'xxx',但是列表选中的却是'最近项目', 切换几次后'最近项目'又不见被替换为'xxx'了,这时列表里有2个'xxx'相册, 虽然可以修改自定义相册collection.isSelected = true稳定这种情况, 但是我们希望弹出相册列表时默认选中的是'xxx',同时'最近项目'也存在,这样可以实现吗?

        _ config: PickerConfiguration,
        options: PHFetchOptions
    ) -> PhotoAssetCollection? {
        if config.creationDate {
            options.sortDescriptors = [
                NSSortDescriptor(
                    key: "creationDate",
                    ascending: config.creationDate
                )
            ]
        }
        var collection: PhotoAssetCollection?
        fetchAssetCollections(options: options) { assetCollection, isCameraRoll, stop in
            if !isCameraRoll, assetCollection.albumName == "xxx" {
                collection = assetCollection
                stop.pointee = true
            }
        }
        if let collection {
//            collection.isSelected = true
            return collection
        }
        return DefaultPhotoFetchAssetCollection.fetchCameraAssetCollection(config, options: options)
    }```
![image](https://github.com/SilenceLove/HXPhotoPicker/assets/12481783/5d31afad-848d-4c9b-8fcd-b3db4aa899e4)



from hxphotopicker.

liumengdi666 avatar liumengdi666 commented on August 15, 2024

我发现可以自定义PhotoFetchData,但是在重写fetchAssetCollections时遇到了一些问题,
image
这两个属性没有public,重写的时候无法使用.
我发现'最近项目'是下边这句代码替换掉的
image
所以我想重写这个方法,不知道重写这个方法是否可行,感觉重写后的select状态依然有些混乱.

from hxphotopicker.

SilenceLove avatar SilenceLove commented on August 15, 2024

你好, 按照上边的方式实现了, 我们采用albumShowMode方式为popup,有点小问题, 比如自定义相册为'xxx', 弹出后点击上边的标题展示albumList会发现显示的是'xxx',但是列表选中的却是'最近项目', 切换几次后'最近项目'又不见被替换为'xxx'了,这时列表里有2个'xxx'相册, 虽然可以修改自定义相册collection.isSelected = true稳定这种情况, 但是我们希望弹出相册列表时默认选中的是'xxx',同时'最近项目'也存在,这样可以实现吗?

        _ config: PickerConfiguration,
        options: PHFetchOptions
    ) -> PhotoAssetCollection? {
        if config.creationDate {
            options.sortDescriptors = [
                NSSortDescriptor(
                    key: "creationDate",
                    ascending: config.creationDate
                )
            ]
        }
        var collection: PhotoAssetCollection?
        fetchAssetCollections(options: options) { assetCollection, isCameraRoll, stop in
            if !isCameraRoll, assetCollection.albumName == "xxx" {
                collection = assetCollection
                stop.pointee = true
            }
        }
        if let collection {
//            collection.isSelected = true
            return collection
        }
        return DefaultPhotoFetchAssetCollection.fetchCameraAssetCollection(config, options: options)
    }```
![image](https://github.com/SilenceLove/HXPhotoPicker/assets/12481783/5d31afad-848d-4c9b-8fcd-b3db4aa899e4)

这个问题下个版本会修改,不会替换掉第一个相册

from hxphotopicker.

liumengdi666 avatar liumengdi666 commented on August 15, 2024

试了最新的修改代码后相册已经不会被替换掉了, 然而发现有一个bug:

https://github.com/SilenceLove/HXPhotoPicker/assets/12481783/927e7131-99b0-4a49-bbb0-dc5862c44434
视频中可以看到打开自定义相册后选中状态有些错乱, 我调试了下大概知道原因:
image

self.cameraAssetCollection可能还没拿到的时候已经走到这个if判断里, 看起来2个queue执行完毕的先后顺序并不能确定,所以时好时坏.

from hxphotopicker.

SilenceLove avatar SilenceLove commented on August 15, 2024

最新的代码试试

from hxphotopicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.