ios最新调用手机相册选取头像(UIActionSheet过期)
由于
UIActionSheet过期所以可以使用如下调用手机相册
前提不要忘记添加代理如下两个
UIImagePickerControllerDelegate,UINavigationControllerDelegate
还需要去plist文件里面添加相机相册权限否则要崩溃的哟
//更换头像
- (IBAction)changeHeadIM:(id)sender {
//创建UIImagePickerController对象,并设置代理和可编辑
UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
imagePicker.editing = YES;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
//创建sheet提示框,提示选择相机还是相册
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"请选择打开方式" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//相机选项
UIAlertAction * camera = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//选择相机时,设置UIImagePickerController对象相关属性
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
//跳转到UIImagePickerController控制器弹出相机
[self presentViewController:imagePicker animated:YES completion:nil];
}];
//相册选项
UIAlertAction * photo = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//选择相册时,设置UIImagePickerController对象相关属性
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//跳转到UIImagePickerController控制器弹出相册
[self presentViewController:imagePicker animated:YES completion:nil];
}];
//取消按钮
UIAlertAction * cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
//添加各个按钮事件
[alert addAction:camera];
[alert addAction:photo];
[alert addAction:cancel];
//弹出sheet提示框
[self presentViewController:alert animated:YES completion:nil];
}
#pragma mark - image picker delegte
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:^{}];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// //原图用image.size.width / image.size.height
// //压缩
// UIGraphicsBeginImageContext(CGSizeMake(800, 600)); //size 为CGSize类型,即你所需要的图片尺寸
// [image drawInRect:CGRectMake(0, 0, 800, 600)];
// UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();
float scales = image.size.height / image.size.width;
UIImage *normalImg;
//如果需要改动被压大小,调整scale,而不是kk或aa
if (image.size.width > 600 || image.size.height > 800) {//这里的1000就是scale,所有的都要随着改变
if (scales > 1) {
CGSize newSize = CGSizeMake(600 / scales, 800);
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
normalImg = UIGraphicsGetImageFromCurrentImageContext();
}else {
CGSize newSize = CGSizeMake(600 ,800 * scales);
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
normalImg = UIGraphicsGetImageFromCurrentImageContext();
}
}else {
normalImg=image;
}
NSData *data = UIImagePNGRepresentation(normalImg);
self.editHeadIM.image = normalImg;
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:^{}];
}
ios最新调用手机相册选取头像(UIActionSheet过期)的更多相关文章
- WebApp调用手机相册或摄像头、拨打电话
WebApp调用手机相册或摄像头.拨打电话 一.总结 一句话总结:input标签,指定type为file,选择好对应的accept即可.camera——相机,相应的accept为image : cam ...
- h5调用手机相册摄像头以及文件夹
在之前一家公司的时候要做一个app里面有上传头像的功能,当时研究了好久,找到了一篇文章关于h5摄像头以及相册的调用的,所以就解决了这个问题了!!我这里记录一下以便后面有人需要,可以参考一下!!!! 下 ...
- web调用手机相册,并实现动态增加图片功能
注:经测试h5调用相册效果有兼容性问题,安卓仅能调用拍照功能(部分安卓可能会调不起来,所以建议用app原生调用),ios可调起拍照和相册功能. <html xmlns="http:// ...
- iOS开发——打开手机相册,获取图片
1.添加代理UIImagePickerControllerDelegate 2.设置点击跳转事件 - (IBAction)picButton:(UIButton *)sender { NSLog(@& ...
- HTML5 调用手机相册和摄像头的方法并上传微信下测试通过
<input type="file" capture="camera" accept="image/*" id="camer ...
- iOS 从手机相册里选取图片
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- H5调用相机和相册更换头像
需求:H5调用手机的相机和相册从而实现更换头像的功能 这个功能是很常用的一个功能,因此做一个记录. 1.在头像img下加一个文件输入框 <input type="file" ...
- IOS调用相机相册
#import "SendViewController.h" //只能打开,没有加载图片的代码,老代码,供参考 #import <MobileCoreServices/UT ...
- ios调用系统相册、相机 显示中文标题、本地化多语言支持
因为调用系统相册.相机需要显示中文,所以搞了半天才知道是在Project->info->Custom ios Target Properties 添加 Localizations 并加入C ...
随机推荐
- oracle10-11数据库下载
Oracle数据库官方下载,需要注册oracle账号,方可下载! 11G 7个压缩包含义: p102025301120——Linux-x86-64_1of7.zip datab ...
- 在centos (linux) 搭建 eclipse c++开发分环境
网上说得很多,很烦,操作了很多,总有错误,但解决方案很简单.步骤就下面几步就OK了 安装gcc .g++ yum install gcc yum install gcc-c++ 安装jdk,配置jdk ...
- java学习之第五章编程题示例(初学篇)
/* Animal.java */ package animal; public abstract class Animal { public abstract void cry(); public ...
- JavaScript:用JS实现加载页面前弹出模态框
用JS实现加载页面前弹出模态框 主要的JavaScript 代码是: <script> //加载模态框 $('#myModal').modal(); $(document).ready(f ...
- 高效开发 Android App 的 10 个建议
假如要Google Play上做一个最失败的案例,那最好的秘诀就是界面奇慢无比.耗电.耗内存.接下来就会得到用户的消极评论,最后名声也就臭了.即使你的应用设计精良.创意无限也没用. 耗电或者内存占用等 ...
- Android开发之模仿UC浏览器的菜单
这个内容内容涉及到的了两个知识点: PopupWindow:使用PopupWindow创建一个简单的菜单 使用TabHost创建标签:这个网上好多教程随便看看就好. 实现思路: 观察一下UC浏览器的菜 ...
- Python学习笔记014——迭代工具函数 内置函数zip()
1 描述 zip() 函数用于将可迭代的对象作为参数,将对象中对应的元素打包成一个个元组,然后返回由这些元组组成的列表. 如果各个迭代器的元素个数不一致,则返回列表长度与最短的对象相同,利用 * 号操 ...
- 开源 java CMS - FreeCMS2.2 单位管理
项目地址:http://www.freeteam.cn/ 单位管理 FreeCMS支持多单位同一时候使用,并支持无限树级管理. 1. 加入根单位 从左側管理菜单点击单位管理进入. 点击"加入 ...
- python 在升级到python2.7之后安装相关插件
# yum update # yum install centos-release-SCL # yum search all python27 在搜索出的列表中发现python27-python-de ...
- [hihoCoder] #1122 : 二分图二•二分图最大匹配之匈牙利算法
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上一回我们已经将所有有问题的相亲情况表剔除了,那么接下来要做的就是安排相亲了.因为过年时间并不是很长,所以姑姑希望能够尽可 ...