打开系统相册,资源库,相机,选择图片
2016-05-23 00:00
363 查看
Swift/OC-->Demo点此下载
// 拍照 if buttonIndex == 1 { /* .Camera 相机 .PhotoLibrary 图库 .Camera 相册 */ let myBool = UIImagePickerController.isSourceTypeAvailable(.Camera); if myBool == false { print("不支持相机"); return; } // 打开相机 openTheImagePickerController(1); return; } // 获取本地相册 if buttonIndex == 2 { // 打开系统资源库 openTheImagePickerController(0); return; }
打开资源库,相机,相册
// MARK: // MARK: 系统资源库,相机,相册 extension <#ViewController#> :UINavigationControllerDelegate,UIImagePickerControllerDelegate { // MARK: // MARK: 打开系统相册 /// 打开系统相册 private func openTheImagePickerController(sourceType: Int) { // 打开相册 // ,UINavigationControllerDelegate,UIImagePickerControllerDelegate let picker = UIImagePickerController(); picker.delegate = self; // 是否 全屏观看 picker.allowsEditing = true; // 资源库 if sourceType == 0 { picker.sourceType = .PhotoLibrary; } // 相机 if sourceType == 1 { picker.sourceType = .Camera; } // 相册 if sourceType == 2 { picker.sourceType = .SavedPhotosAlbum; } // 跳转控制器 presentViewController(picker, animated: true, completion: nil); } // MARK: // MARK: 选择 Choose 调用此方法 /// 选择 Choose 调用此方法 func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { // 关闭控制器 picker.dismissViewControllerAnimated(true, completion: nil); // 获取 图片 let image = info["UIImagePickerControllerOriginalImage"] as? UIImage ; myImageView.image = image; /* 此处info 有六个值 * UIImagePickerControllerMediaType; // an NSString UTTypeImage) * UIImagePickerControllerOriginalImage; // a UIImage 原始图片 * UIImagePickerControllerEditedImage; // a UIImage 裁剪后图片 * UIImagePickerControllerCropRect; // an NSValue (CGRect) * UIImagePickerControllerMediaURL; // an NSURL * UIImagePickerControllerReferenceURL // an NSURL that references an asset in the AssetsLibrary framework * UIImagePickerControllerMediaMetadata // an NSDictionary containing metadata from a captured photo */ } }
判断是否支持资源库,相机,相册
相关文章推荐
- ORACLE中date类型字段的处理
- js图片放大缩小
- java伪造http请求多文件上传
- django的admin 管理
- nginx配置多个项目(不同的tomcat)
- URL实用函数
- 复制内容到系统剪贴板(无flash)
- 发起JSONP请求
- color实用函数
- 供应链身份
- RMT导出Excel
- NSRunloop,runloop,autoReleasePool和thread的关系理解及案例解决
- iOS开发CoreAnimation解读之一——初识CoreAnimation核心动画编程
- 制作自定义的字体图标
- js格式化日期
- FLV video tag
- ffmpeg print_report说明: 一转一
- ffmpeg print_report说明: 一转多
- js 判断 用户浏览器所在平台
- Java 项目常用变量命名