//
// SendViewController.m
// WeiNiXieShi
//
// Created by vshine on 14-5-18.
// Copyright (c) 2014年 wdl. All rights reserved.
//
#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调用相机相册(1)
最新推荐文章于 2021-11-27 21:43:48 发布