IOS调用相机相册

  1. #import "SendViewController.h"  //只能打开,没有加载图片的代码,老代码,供参考
  2. #import <MobileCoreServices/UTCoreTypes.h>
  3. @interface SendViewController ()<UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
  4. -(IBAction)selectDescPic:(id)sender;
  5. @end
  6. @implementation SendViewController
  7. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  8. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  9. if (self) {
  10. }
  11. return self;
  12. }
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. }
  16. - (void)didReceiveMemoryWarning {
  17. [super didReceiveMemoryWarning];
  18. }
  19. -(IBAction)selectDescPic:(id)sender {
  20. UIActionSheet *actionSheet = [[UIActionSheet alloc]
  21. initWithTitle:nil
  22. delegate:self
  23. cancelButtonTitle:@"取消"
  24. destructiveButtonTitle:nil
  25. otherButtonTitles:@"拍照", @"从手机相册选择",nil];
  26. actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
  27. [actionSheet showInView:self.view];
  28. }
  29. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  30. if (buttonIndex == 0) {
  31. UIImagePickerController *camera = [[UIImagePickerController alloc] init];
  32. camera.delegate = self;
  33. camera.allowsEditing = NO;
  34. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  35. camera.sourceType = UIImagePickerControllerSourceTypeCamera;
  36. //此处设置只能使用相机,禁止使用视频功能
  37. camera.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];
  38. } else {
  39. NSLog(@"相机功能不可用");
  40. return;
  41. }
  42. [self presentViewController:camera animated:YES completion:nil];
  43. } else if (buttonIndex == 1) {
  44. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  45. picker.delegate = self;
  46. picker.allowsEditing = NO;
  47. //从相册列表选取
  48. picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  49. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
  50. //此处设置只能使用相机,禁止使用视频功能
  51. picker.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];
  52. }
  53. [self presentViewController:picker animated:YES completion:nil];
  54. } else if(buttonIndex == 2) {
  55. //取消
  56. }
  57. }
  58. @end
时间: 2024-08-06 03:42:42

IOS调用相机相册的相关文章

iOS调用相机,相册,上传头像

一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAction)chooseImage:(id)sender { UIActionSheet *sheet; // 判断是否支持相机 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCam

IOS调用相机和相册时无法显示中文

调用系统相册.相机发现是英文的系统相簿界面后标题显示“photos”,但是手机语言已经设置显示中文 需要在info.plist做如下设置 info.plist里面添加 Localizedresources can be mixed YES Localization native development region China 表示是否允许应用程序获取框架库内语言.

iOS调用系统相册、相机 显示中文标题

最近做头像上传功能需要使用系统相册.相机,在调用系统相册.相机发现是英文的系统相簿界面后标题显示"photos",但是手机语言已经设置显示中文,纠结半天,最终在info.plist设置解决问题. 发现在项目的info.plist里面添加Localized resources can be mixed YES(表示是否允许应用程序获取框架库内语言)即可解决这个问题.特此记录下以便以后查看和别人解决问题

iOS开发-iOS调用相机调用相册【将图片保存到本地相册】

设置头部代理 <UINavigationControllerDelegate, UIImagePickerControllerDelegate> 1.调用相机 检测前置摄像头是否可用 - (BOOL)isFrontCameraAvailable{ return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]; } 检测后置摄像头是否可用 - (BOOL)isRe

iOS 10 相机-相册-通讯录权限问题

手机升级到iOS10,升级Xcode 8,连上手机,开始调试.你会发现在调用相机.相册.通讯录时,程序崩溃,报出权限错误.既然有坑就去填坑咯.话不多说,直接看解决办法. 直接在info.plist点击加好号,重新添加一个,Type选择为String,直接输入Privacy,点击一下右侧的那个小按钮, 就能看到很多key啦.如下图: 常用的key有相机的,相册的,联系人的.这些在iOS 10 都要添加,不然都不会弹出获取权限的弹窗.可以使用这些key: Privacy - Photo Librar

多媒体之调用相机相册及视频播放

1 #import "RootViewController.h" 2 #import <MediaPlayer/MediaPlayer.h> 3 #import <MobileCoreServices/MobileCoreServices.h> //存放了系统调用的常量 4 @interface RootViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDeleg

ios 调用相机后 view 下沉问题

我只加了一句代码 现在不报错了  因为这个问题是随机性的  我也不太明白这个地方是怎么回事   我只是这样子做了  问题不出来了 if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) { _imagePicker.modalPresentationStyle=UIModalPresentationOverCurrentContext; }

ios调用相机之后状态栏消失

Apparently, in addition to setting the status bar to not be hidden, you also have to reset its style after the camera view makes it disappear. Try this: [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO]; [[UIApplication sharedAppl

调用相机,选择图片上传,带预览功能、图片压缩、相机文字设置、

摘要 iOS调用相机,iOS调用相册,保存至应用程序沙盒,高保真压缩图片,并有点击放大预览,再次点击缩回至原大小,带动画效果,附源码下载地址. Xcode版本4.5.1 类库ios6.0 IOS调用相机 图片预览 图片上传 压缩图片 模拟器添加图片 目录[-] 判断是否支持相机,跳转到相机或相册界面 七.保存图片 高保真压缩图片方法 八.实现点击图片预览功能,滑动放大缩小,带动画 ps:模拟器添加图片 源码下载地址: 一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate ? 1