123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- /*
-
- MIT License (MIT)
-
- Copyright (c) 2015 Clement CN Tsang
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-
- */
- #import <UIKit/UIKit.h>
- #import <Photos/Photos.h>
- NS_ASSUME_NONNULL_BEGIN
- @protocol CTAssetsPickerControllerDelegate;
- /**
- * A controller that allows picking multiple photos and videos from user's photo library.
- */
- @interface CTAssetsPickerController : UIViewController
- /**
- * The assets picker’s delegate object.
- */
- @property (nonatomic, weak) id <CTAssetsPickerControllerDelegate> delegate;
- /**
- * Set the `assetCollectionSubtypes` to specify which asset collections (albums) to be shown in the picker.
- *
- * You can specify which albums and their order to be shown in the picker by creating an `NSArray` of `NSNumber`
- * that containing the value of `PHAssetCollectionSubtype`.
- */
- @property (nonatomic, copy) NSArray<NSNumber*> *assetCollectionSubtypes;
- /**
- * Set the `defaultAssetCollection` to specify which asset collection (album) is the default asset collection.
- *
- * If the `defaultAssetCollection` is explictly set, the picker initially shows the content of default asset
- * collection instead of a list of albums. By default, there are no default asset collection.
- *
- * If there are more than one asset collections that match the subtype value of `defaultAssetCollection`, the
- * first matched asset collection will be the default asset collection.
- */
- @property (nonatomic, assign) PHAssetCollectionSubtype defaultAssetCollection;
- /**
- * Set the `PHFetchOptions` to specify options when fetching asset collections (albums).
- *
- * @see assetsFetchOptions
- */
- @property (nonatomic, strong) PHFetchOptions *assetCollectionFetchOptions;
- /**
- * Set the `PHFetchOptions` to specify options when fetching assets.
- *
- * @see assetCollectionFetchOptions
- */
- @property (nonatomic, strong) PHFetchOptions *assetsFetchOptions;
- /**
- * The selected assets.
- *
- * It contains selected `PHAsset` objects. The order of the objects is the selection order.
- *
- * You can use this property to select assets initially when presenting the picker.
- */
- @property (nonatomic, strong) NSMutableArray *selectedAssets;
- /**
- * An optional title for the done button
- *
- * You can override the title of "Done" button by this value.
- */
- @property (nonatomic, copy) NSString *doneButtonTitle;
- /**
- * Determines whether or not the cancel button is visible in the picker.
- *
- * The cancel button is visible by default. To hide the cancel button, (e.g. presenting the picker in `UIPopoverController`)
- * set this property’s value to `NO`.
- */
- @property (nonatomic, assign) BOOL showsCancelButton;
- /**
- * Determines whether or not the empty albums is shown in the album list.
- *
- * All albums are visible by default. To hide albums without assets matched with `assetsFetchOptions`,
- * set this property’s value to `NO`.
- *
- * @see assetsFetchOptions
- */
- @property (nonatomic, assign) BOOL showsEmptyAlbums;
- /**
- * Determines whether or not the number of assets is shown in the album list.
- *
- * The number of assets is visible by default. To hide the number of assets, (e.g. implementing `shouldShowAsset` delegate method)
- * set this property’s value to `NO`.
- */
- @property (nonatomic, assign) BOOL showsNumberOfAssets;
- /**
- * Determines whether or not the done button is always enabled.
- *
- * The done button is enabled only when assets are selected. To enable the done button even without assets selected,
- * set this property’s value to `YES`.
- */
- @property (nonatomic, assign) BOOL alwaysEnableDoneButton;
- /**
- * Determines whether or not the selection order is shown in the grid view.
- *
- * Only a checkmark is shown on selected assets by default. To shows the order of selection,
- * set this property’s value to `YES`.
- */
- @property (nonatomic, assign) BOOL showsSelectionIndex;
- /**
- * The split view controller of the picker hierarchy. (read-only)
- *
- * This property contains the child split view controller of the picker.
- */
- @property (nonatomic, readonly, strong) UISplitViewController *childSplitViewController;
- /**
- * @name Managing Selections
- */
- /**
- * Selects an asset in the picker.
- *
- * @param asset The asset to be selected.
- *
- * @see deselectAsset:
- */
- - (void)selectAsset:(PHAsset *)asset;
- /**
- * Deselects an asset in the picker.
- *
- * @param asset The asset to be deselected.
- *
- * @see selectAsset:
- */
- - (void)deselectAsset:(PHAsset *)asset;
- @end
- /**
- * The `CTAssetsPickerControllerDelegate` protocol defines methods that allow you to to interact with the assets picker interface
- * and manage the selection and highlighting of assets in the picker.
- *
- * The methods of this protocol notify your delegate when the user selects, highlights, finish picking assets, or cancels the picker operation.
- *
- * The delegate methods are responsible for dismissing the picker when the operation completes.
- * To dismiss the picker, call the `dismissViewControllerAnimated:completion:` method of the presenting controller
- * responsible for displaying `CTAssetsPickerController` object.
- *
- * The picked assets are `PHAsset` objects and contain only metadata. The underlying image or video data for any given asset might not be stored on the local device.
- * You have to use `PHImageManager` object for loading image or video data associated with a `PHAsset`.
- */
- @protocol CTAssetsPickerControllerDelegate <NSObject>
- /**
- * @name Closing the Picker
- */
- /**
- * Tells the delegate that the user finish picking photos or videos.
- *
- * @param picker The controller object managing the assets picker interface.
- * @param assets An array containing picked `PHAsset` objects.
- *
- * @see assetsPickerControllerDidCancel:
- */
- - (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray<PHAsset*> *)assets;
- @optional
- /**
- * Tells the delegate that the user cancelled the pick operation.
- *
- * @param picker The controller object managing the assets picker interface.
- *
- * @see assetsPickerController:didFinishPickingAssets:
- */
- - (void)assetsPickerControllerDidCancel:(CTAssetsPickerController *)picker;
- /**
- * @name Configuting Asset Selection View
- */
- /**
- * Ask the delegate the layout of asset selection view (UICollectionView).
- *
- * @param picker The controller object managing the assets picker interface.
- * @param contentSize The bounds size of current view.
- * @param trait The trait collection of current view.
- *
- * @return Custom `UICollectionViewLayout` for the asset selection view.
- */
- - (UICollectionViewLayout *)assetsPickerController:(CTAssetsPickerController *)picker collectionViewLayoutForContentSize:(CGSize)contentSize traitCollection:(UITraitCollection *)trait;
- /**
- * Ask the delegate if the asset selection view should sroll to bottom on shown.
- *
- * @param picker The controller object managing the assets picker interface.
- * @param assetCollection The asset collection of asset selection view.
- *
- * @return `YES` (the default) if the asset grid should scroll to bottom on shown or `NO` if it should not.
- */
- - (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldScrollToBottomForAssetCollection:(PHAssetCollection *)assetCollection;
- /**
- * @name Enabling Assets
- */
- /**
- * Ask the delegate if the specified asset should be enabled for selection.
- *
- * @param picker The controller object managing the assets picker interface.
- * @param asset The asset to be enabled.
- *
- * @return `YES` if the asset should be enabled or `NO` if it should not.
- *
- * @see assetsPickerController:shouldShowAsset:
- */
- - (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldEnableAsset:(PHAsset *)asset;
- /**
- * @name Managing the Selected Assets
- */
- /**
- * Asks the delegate if the specified asset should be selected.
- *
- * @param picker The controller object managing the assets picker interface.
- * @param asset The asset to be selected.
- *
- * @return `YES` if the asset should be selected or `NO` if it should not.
- *
- * @see assetsPickerController:shouldDeselectAsset:
- */
- - (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldSelectAsset:(PHAsset *)asset;
- /**
- * Tells the delegate that the asset was selected.
- *
- * @param picker The controller object managing the assets picker interface.
- * @param asset The asset that was selected.
- *
- * @see assetsPickerController:didDeselectAsset:
- */
- - (void)assetsPickerController:(CTAssetsPickerController *)picker didSelectAsset:(PHAsset *)asset;
- /**
- * Asks the delegate if the specified asset should be deselected.
- *
- * @param picker The controller object managing the assets picker interface.
- * @param asset The asset to be deselected.
- *
- * @return `YES` if the asset should be deselected or `NO` if it should not.
- *
- * @see assetsPickerController:shouldSelectAsset:
- */
- - (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldDeselectAsset:(PHAsset *)asset;
- /**
- * Tells the delegate that the item at the specified path was deselected.
- *
- * @param picker The controller object managing the assets picker interface.
- * @param asset The asset that was deselected.
- *
- * @see assetsPickerController:didSelectAsset:
- */
- - (void)assetsPickerController:(CTAssetsPickerController *)picker didDeselectAsset:(PHAsset *)asset;
- /**
- * @name Managing Asset Highlighting
- */
- /**
- * Asks the delegate if the specified asset should be highlighted.
- *
- * @param picker The controller object managing the assets picker interface.
- * @param asset The asset to be highlighted.
- *
- * @return `YES` if the asset should be highlighted or `NO` if it should not.
- */
- - (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldHighlightAsset:(PHAsset *)asset;
- /**
- * Tells the delegate that asset was highlighted.
- *
- * @param picker The controller object managing the assets picker interface.
- * @param asset The asset that was highlighted.
- *
- * @see assetsPickerController:didUnhighlightAsset:
- */
- - (void)assetsPickerController:(CTAssetsPickerController *)picker didHighlightAsset:(PHAsset *)asset;
- /**
- * Tells the delegate that the highlight was removed from the asset.
- *
- * @param picker The controller object managing the assets picker interface.
- * @param asset The asset that had its highlight removed.
- *
- * @see assetsPickerController:didHighlightAsset:
- */
- - (void)assetsPickerController:(CTAssetsPickerController *)picker didUnhighlightAsset:(PHAsset *)asset;
- /**
- * @name Notifications
- */
- /**
- * Sent when the assets selected or deselected
- *
- * The notification’s `object` is an `NSArray` object of selected assets
- */
- extern NSString * const CTAssetsPickerSelectedAssetsDidChangeNotification;
- /**
- * Sent when asset is selected
- *
- * The notification’s `object` is a `PHAsset` that is selected
- */
- extern NSString * const CTAssetsPickerDidSelectAssetNotification;
- /**
- * Sent when asset is deselected
- *
- * The notification’s `object` is a `PHAsset` that is deselected
- */
- extern NSString * const CTAssetsPickerDidDeselectAssetNotification;
- @end
- NS_ASSUME_NONNULL_END
|