ios中调用相机,相册,选择多张图片
2015-09-12 16:48
423 查看
参考Demo http://yunpan.cn/cmDTGIcii9B4d (提取码:0838)
我自己的demo https://yunpan.cn/cuVkzZGWvj7P5 (提取码:810f)
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (![QBImagePickerControllerisAccessible]) {
NSLog(@"Error: Source is not accessible.");
}
//通过按钮触发选择相机,相册
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];
button.frame =CGRectMake(100,100,
100,100);
button.backgroundColor = [UIColorredColor];
[button addTarget:selfaction:@selector(buttonclick)forControlEvents:UIControlEventTouchUpInside];
button.tag =100;
[self.viewaddSubview:button];
}
-(void)buttonclick{
QBImagePickerController *imagePickerController = [[QBImagePickerControlleralloc]
init];
imagePickerController.delegate =self;
/*
//选择图片的至少张数和最多张数
//imagePickerController.minimumNumberOfSelection =3;
// imagePickerController.maximumNumberOfSelection =6;
*/
imagePickerController.maximumNumberOfSelection =9;
imagePickerController.allowsMultipleSelection =YES;
UINavigationController *navigationController = [[UINavigationControlleralloc]
initWithRootViewController:imagePickerController];
[selfpresentViewController:navigationControlleranimated:YEScompletion:NULL];
}
/*
回调方法
*/
- (void)dismissImagePickerController
{
if (self.presentedViewController) {
[selfdismissViewControllerAnimated:YEScompletion:NULL];
} else {
[self.navigationControllerpopToViewController:selfanimated:YES];
}
}
#pragma mark - QBImagePickerControllerDelegate
- (void)imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(ALAsset
*)asset
{
NSLog(@"*** imagePickerController:didSelectAsset:");
NSLog(@"%@", asset);
[selfdismissImagePickerController];
}
- (void)imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray
*)assets
{
NSLog(@"*** imagePickerController:didSelectAssets:");
NSLog(@"%@", assets);
[selfdismissImagePickerController];
}
- (void)imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController
{
NSLog(@"*** imagePickerControllerDidCancel:");
[selfdismissImagePickerController];
}
我自己的demo https://yunpan.cn/cuVkzZGWvj7P5 (提取码:810f)
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (![QBImagePickerControllerisAccessible]) {
NSLog(@"Error: Source is not accessible.");
}
//通过按钮触发选择相机,相册
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];
button.frame =CGRectMake(100,100,
100,100);
button.backgroundColor = [UIColorredColor];
[button addTarget:selfaction:@selector(buttonclick)forControlEvents:UIControlEventTouchUpInside];
button.tag =100;
[self.viewaddSubview:button];
}
-(void)buttonclick{
QBImagePickerController *imagePickerController = [[QBImagePickerControlleralloc]
init];
imagePickerController.delegate =self;
/*
//选择图片的至少张数和最多张数
//imagePickerController.minimumNumberOfSelection =3;
// imagePickerController.maximumNumberOfSelection =6;
*/
imagePickerController.maximumNumberOfSelection =9;
imagePickerController.allowsMultipleSelection =YES;
UINavigationController *navigationController = [[UINavigationControlleralloc]
initWithRootViewController:imagePickerController];
[selfpresentViewController:navigationControlleranimated:YEScompletion:NULL];
}
/*
回调方法
*/
- (void)dismissImagePickerController
{
if (self.presentedViewController) {
[selfdismissViewControllerAnimated:YEScompletion:NULL];
} else {
[self.navigationControllerpopToViewController:selfanimated:YES];
}
}
#pragma mark - QBImagePickerControllerDelegate
- (void)imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(ALAsset
*)asset
{
NSLog(@"*** imagePickerController:didSelectAsset:");
NSLog(@"%@", asset);
[selfdismissImagePickerController];
}
- (void)imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray
*)assets
{
NSLog(@"*** imagePickerController:didSelectAssets:");
NSLog(@"%@", assets);
[selfdismissImagePickerController];
}
- (void)imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController
{
NSLog(@"*** imagePickerControllerDidCancel:");
[selfdismissImagePickerController];
}
相关文章推荐
- ios多线程
- iOS数据持久化(一)
- IOS中如何异步加载图片(三)KVO观察者
- ios开发系列之触摸事件
- iGrimaceV8 V8在线威锋源apt.so/tuzhurenv8手机直接下载安装教程图:
- iOS沙盒机制和文件操作
- iOS 数组和字典排序
- IOS - 定时器
- iOS7隐藏状态栏 statusBar
- IOS中如何异步加载图片(一)封装自己的ImageDownLoad类
- iOS导航栏NavigationBar的颜色,按钮和标题以及字体颜色
- IOS-ScorllView
- IOS开发者常用的10个Xcode插件
- 蓝懿学习之 练习日
- igrimaceV8.0.0 IG 一键新机 陌陌 Uber优步打针 平安易贷 滴滴 一号专车 饿了么 ios8 V8 ZTN(插件安装方式)
- iOS 裁剪图片
- iOS中property和synthesize的详细说明
- iOS学习笔记-多线程基础(NSThread)
- iOS9的广告屏蔽功能在谷歌背后捅了致命一刀?
- 招聘一个靠谱的ios(上)答案