swift 实现拍照 选择相册
//点击按钮的方法
func photos() { self.showBottomAlert() }
/// 屏幕底部弹出的Alert
func showBottomAlert(){ let alertController=UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let cancel=UIAlertAction(title:"取消", style: .cancel, handler: nil)
let takingPictures=UIAlertAction(title:"拍照", style: .default)
{
action in
self.goCamera() }
let localPhoto=UIAlertAction(title:"本地图片", style: .default)
{
action in
self.goImage() }
alertController.addAction(cancel)
alertController.addAction(takingPictures)
alertController.addAction(localPhoto)
self.present(alertController, animated:true, completion:nil) }
//拍照与本地相册方法/
// 去拍照
func goCamera(){ if UIImagePickerController.isSourceTypeAvailable(.camera){
let cameraPicker = UIImagePickerController()
cameraPicker.delegate = self
cameraPicker.allowsEditing = true
cameraPicker.sourceType = .camera
//在需要的地方present出来
self.present(cameraPicker, animated: true, completion: nil)
} else { print("不支持拍照") } }
/// 去相册
func goImage(){ let photoPicker = UIImagePickerController()
photoPicker.delegate = self
photoPicker.allowsEditing = true
photoPicker.sourceType = .photoLibrary
//在需要的地方present出来
self.present(photoPicker, animated: true, completion: nil) }
//代理
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { print("获得照片============= \(info)") let image : UIImage = info[UIImagePickerController.InfoKey.editedImage] as! UIImage //显示设置的照片
imgView.image = image self.dismiss(animated: true, completion: nil)
}
作者:江河_ios
链接:https://www.jianshu.com/p/fc0768999ef8
swift 实现拍照 选择相册的更多相关文章
- Swift - 使用UIImagePickerController从相册选择照片并展示
1,UIImagePickerController介绍 (1)选择相册中的图片或者拍照,都是通过UIImagePickerController控制器实例化一个对象,然后通过self.presentVi ...
- HTML5 Plus 拍照或者相册选择图片上传
HBuilder+HTML5 Plus+MUI实现拍照或者相册选择图片上传,利用HTML5 Plus的Camera.Gallery.IO.Storage和Uploader来实现手机APP拍照或者从相册 ...
- 调用原生硬件 Api 实现照相机 拍照和相册选择 以及拍照上传
一.Flutter image_picker 实现相机拍照和相册选择 https://pub.dev/packages/image_picker 二.Flutter 上传图片到服务器 ht ...
- iOS9中,swift判断相机,相册权限,选取图片为头像
在iOS7以后要打开手机摄像头或者相册的话都需要权限,在iOS9中更是更新了相册相关api的调用 首先新建一个swift工程,在SB中放上一个按钮,并在viewController中拖出点击事件 ok ...
- android拍照选择图片上传服务器自定义控件
做android项目的时候总免不了遇到图片上传功能,虽然就是调用android系统的拍照和相册选择功能,但是总面部了把一大推代码写在activity里,看上去一大推代码头都昏了.不如把这些功能都集成一 ...
- swift调用相机和相册
简单实现swift调用相机和相册的功能,分享代码与学习swift的童鞋共同进步 import UIKit class ViewController: UIViewController,UIImageP ...
- Android拍照与相册选取图片
做过几次拍照,相册选取图片,但都记不住,这次发表个简单的保存下 private static final int PHOTO_GRAPH = 1;// 拍照 private static final ...
- Xamarin开发Android笔记:拍照或相册选取图片角度问题
在开发Android应用的时候,可能会遇到类似微信朋友圈中拍照或相册选取图片的场景,拍照或选取图片之后在显示的时候却发现图片的角度不对,明明是竖版拍照,显示出来缺失躺着的. 这是因为在某些特定手机上例 ...
- android——拍照,相册图片剪切其实就这么简单
接触android这么久了.还没有真正的浩浩看看android拍照,相册图片剪切到底是怎么回事,每次都是从别人的代码一扣,就过来了.其实,谷歌提供的API已经很强大.只需要用的好,就那么几句就可以搞定 ...
随机推荐
- Android 开发 将window变暗
前言 在创建弹窗功能时,一般有需求将背景的window界面变暗.下面两组代码就实现了变暗与恢复的功能. 变暗 public void startDark(){ WindowManager.Layout ...
- Mui中常见问题记录
1.mui中A标签如果有这个class="mui-control-item"时,a标签点击链接是没有反应的,那么可以用以下方式实现 : mui.init(); mui('body' ...
- add-migration Build failed.
>add-migration JczInfoDateTimeBuild failed. 1编译解决方案,看是否报错,不管哪个有错误都会迁移失败 2重启vs
- 70.纯 CSS 创作一只徘徊的果冻怪兽
原文地址:https://segmentfault.com/a/1190000015484852 感想:monster中边框角.上下动画.旋转动画.左右动画,眼睛中transform:scaleY(n ...
- SQLserver登陆报错
https://blog.csdn.net/captain618/article/details/52331372 今天也不知道sql server抽了什么风,无论是windows登录还是sa登录,登 ...
- nginx的命令
- NGINX轻松管理10万长连接
先说说服务为什么使用HTTPs长连接技术?有如下几个原因:对响应时间要求较高:服务走的是公网,客户端与服务端的TCP建立的三次握手和断开的四次握手都需要40ms左右(真实数据包计算出来的),共需要80 ...
- 500G !!史上最全的JAVA全套教学视频网盘分享 (JEECG开源社区)
500 G JAVA视频网盘分享(JEECG开源社区) [涵盖从java入门到深入架构,Linux.云计算.分布式.大数据Hadoop.ios.Android.互联网技术应有尽有] JEECG开源社区 ...
- 根据设备width(375)动态设置font-size
根据html的font-size使用rem来优化移动端页面 (function () { var w = window, d = document.documentElement, t; var re ...
- Prometheus
官方网址:https://prometheus.io/ GitHub网址:https://github.com/prometheus/prometheus 软件下载地址:https://prometh ...