一个类似 UIImagePickerController 的资产选择器,它利用 ARMultiSelectGestureRecognizer
进行滑动选择
将 ARSwipeToSelectPickerController
添加到您的项目最简单的方法是通过 CocoaPods
pod 'ARSwipeToSelectPickerController'
或者,您可以将 Classes/
目录中的所有文件复制到您的项目中。确保已勾选“将项目复制到目标文件夹”。
#import "ARSwipeToSelectPickerController.h"
ARSwipeToSelectPickerControllerDelegate
协议,实现其 代理方法ARSwipeToSelectPickerController *picker = [[ARSwipeToSelectPickerController alloc] initWithDelegate:self];
[self.navigationController pushViewController:picker animated:YES];
您还可以先将其嵌入到 UINavigationController
中以模式显示选择器
ARSwipeToSelectPickerController *picker = [[ARSwipeToSelectPickerController alloc] initWithDelegate:self];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:picker];
[self presentViewController:nav animated:YES completion:nil];
#pragma mark - ARSwipeToSelectPickerControllerDelegate methods
- (void) swipeToSelectPickerControllerDidCancel:(ARSwipeToSelectPickerController *)sender
{
// use popViewControllerAnimated if using navigation controller for viewcontroller stack
//[self.navigationController popViewControllerAnimated:YES];
// use dismissViewControllerAnimated if not using a navigation controller
//[self dismissViewControllerAnimated:YES completion:nil];
}
- (void) swipeToSelectPickerController:(ARSwipeToSelectPickerController *)sender didFinishPickingMediaWithAssets:(NSArray *)assets
{
// Use MWPhotoBrowser to show the selected photos
[self dismissViewControllerAnimated:NO completion:^{
NSMutableArray *tmpArray = [[NSMutableArray alloc] initWithCapacity:[assets count]];
[assets enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIImage *image = [UIImage imageWithCGImage:[[((ALAsset *) obj) defaultRepresentation] fullScreenImage]];
[tmpArray addObject:[MWPhoto photoWithImage:image]];
}];
self.photos = tmpArray;
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
browser.displayActionButton = NO;
[browser setInitialPageIndex:0];
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:browser animated:YES completion:nil];
});
}];
}
或者如果您在 UINavigationController
栈中,可以执行以下操作来关闭选择器控制器
[self.navigationController popToViewController:self animated:YES];
您可以在 演示文件夹 找到一个令人印象深刻的演示!