iOS 晋级之路- 调用相机和相册的功能
最近在做一款跟相机有关的应用,也是实现自己的一个小小的梦想,哈哈,闲话不多说!上代码
1.设定sourceType为相机
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera
//这里
2.判断设备是否有相机(当然模拟器一定是没有摄像头的)
if(![UIImagePickerContrller isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])//这个方法可以判断设备是否有摄像头
{
soureceType = UIImagePickerControllerSourceTypePhotoLibrary;//在这里如果没有摄像头的话我们就将资源射程相册
}
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;//这里记得要设置控制器的代理<UIImagePickerControllerDelegate>
picker.allowsEditing = yes;//设置可编辑
picker.sourceType = sourceType;
[self presentModalViewController:picker animated:yes];//进入相册
注意设置完代理之后:
点击相册中的图片 货照相机照完后点击use 后触发的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
点击cancel 调用的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker