您的位置:首页 > 移动开发 > IOS开发

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];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: