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];
}
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];
}
相关文章推荐
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- iOS UITableView设置表头和表脚
- UE3常见技术问题
- EasyUI中dialog中嵌入form细节问题记录
- UE3代码阅读需知
- 自定义UITableViewCell复用分享
- selenium问题六:上传文件报错WebDriverException: Message: '{"value" : "Command not found:
- 使UILable中出现不同的字体、字号与颜色 ------ 使用AttributedString
- iOS开发日记41-9.0布局神器UIStackView
- UILable,UIButton的富文本显示
- Servlet获取Request和Response
- GPUImage滤镜效果
- 获得GPUImage处理后的UIImage
- 设置UILable文本的粗体其他字体
- UILabel 文案添加下划线
- iOS开发 仿相册的一个小Demo 相关UICollectionView,UIScrollView,AFNetworking
- UIImage保存到相册
- Leetcode -- Distinct Subsequences
- EasyUI datagrildview导出excel报表
- 杭电ACM-HDU1005-Number Sequence