IOS7-UIImagePickerController使用

@interface CapturePicViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@property(nonatomic,retain) UIImagePickerController *imgPickerCtl;
@end

@implementation CapturePicViewController
@synthesize imgPickerCtl;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self loadImgPicker];
    
}
- (void)loadImgPicker
{
    imgPickerCtl = [[UIImagePickerController alloc]init];
    //調用攝像頭捕捉圖片顯示出來
    //Camera
    imgPickerCtl.sourceType = UIImagePickerControllerSourceTypeCamera;
    //讀取相冊的圖片顯示出來
    //photo library
    //imgPickerCtl.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imgPickerCtl.delegate = self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self presentViewController:imgPickerCtl animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [imgPickerCtl dismissViewControllerAnimated:YES completion:^{
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
        [self.view addSubview:imageView];
    }];
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章