- #import "SendViewController.h" //只能打开,没有加载图片的代码,老代码,供参考
- #import <MobileCoreServices/UTCoreTypes.h>
- @interface SendViewController ()<UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
- -(IBAction)selectDescPic:(id)sender;
- @end
-
- @implementation SendViewController
-
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
-
- }
- return self;
- }
-
- - (void)viewDidLoad {
- [super viewDidLoad];
- }
-
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
-
- -(IBAction)selectDescPic:(id)sender {
- UIActionSheet *actionSheet = [[UIActionSheet alloc]
- initWithTitle:nil
- delegate:self
- cancelButtonTitle:@"取消"
- destructiveButtonTitle:nil
- otherButtonTitles:@"拍照", @"从手机相册选择",nil];
- actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
- [actionSheet showInView:self.view];
- }
-
- -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
- if (buttonIndex == 0) {
- UIImagePickerController *camera = [[UIImagePickerController alloc] init];
- camera.delegate = self;
- camera.allowsEditing = NO;
-
- if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
- camera.sourceType = UIImagePickerControllerSourceTypeCamera;
- //此处设置只能使用相机,禁止使用视频功能
- camera.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];
- } else {
- NSLog(@"相机功能不可用");
- return;
- }
- [self presentViewController:camera animated:YES completion:nil];
- } else if (buttonIndex == 1) {
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];
- picker.delegate = self;
- picker.allowsEditing = NO;
- //从相册列表选取
- picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
-
- if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
- //此处设置只能使用相机,禁止使用视频功能
- picker.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage,nil];
- }
- [self presentViewController:picker animated:YES completion:nil];
- } else if(buttonIndex == 2) {
- //取消
- }
- }
-
-
- @end
IOS调用相机相册
原文:http://www.cnblogs.com/isItOk/p/4873100.html