您的位置:首页 > 产品设计 > UI/UE

UIImagePickerController 拍照

2015-10-30 15:26 281 查看
@interface
TestAlertViewController ()<UIActionSheetDelegate,
UIImagePickerControllerDelegate, UINavigationControllerDelegate>

@property (nonatomic,strong )
IBOutlet UIImageView *phonoImage;

@property (nonatomic,strong )
UIImagePickerController *imagePikerViewController;

@end

@implementation TestAlertViewController

- (void)viewDidLoad {

[super
viewDidLoad];

self.imagePikerViewController = [[UIImagePickerController
alloc]init];

self.imagePikerViewController.delegate =
self;

self.phonoImage.contentMode
= UIViewContentModeScaleAspectFit;

}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id>
*)info{

UIImage *image = info[UIImagePickerControllerEditedImage];

if (!image) {

image = info[UIImagePickerControllerOriginalImage];

}

self.phonoImage.image = image;

[self
dismissViewControllerAnimated:YES
completion:NULL];

}

-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{

[self
dismissViewControllerAnimated:YES
completion:NULL];

}

- (IBAction)alertButton:(UIButton *)sender {

UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleAlert];

[alertController addAction:[UIAlertAction
actionWithTitle:@"拍照"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *
_Nonnull action) {

//处理拍照

if ([UIImagePickerController
isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

self.imagePikerViewController.sourceType
= UIImagePickerControllerSourceTypeCamera;

[self
presentViewController:self.imagePikerViewController
animated:YES
completion:NULL];

}

}]];

[alertController addAction:[UIAlertAction
actionWithTitle:@"从相册中选取"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *
_Nonnull action) {

//从相册中选取

if ([UIImagePickerController
isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){

self.imagePikerViewController.sourceType
= UIImagePickerControllerSourceTypePhotoLibrary;

[self
presentViewController:self.imagePikerViewController
animated:YES
completion:NULL];

}

}]];

[alertController addAction:[UIAlertAction
actionWithTitle:@"取消"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *
_Nonnull action) {

}]];

[self
presentViewController:alertController animated:YES
completion:nil];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: