<UI>点击UIImageView实现相册的调用

主要是UIImagePickerControllerDelegate协议的实现

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *oneTouch = [touches anyObject];
    UIView *touchView = oneTouch.view;
    // 判断如果点击到图片了
    if (touchView == previewImageView) {
        UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
        // UIImagePickerController相册和相机
    //    ipc.sourceType = UIImagePickerControllerSourceTypeCamera;       ipc.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
        ipc.delegate = self;
        [self presentModalViewController:ipc animated:YES];
        // 启动
        [ipc release];
    }
}
// 相册的代理函数 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    // 取得选中的图片
    UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];
    // 取得选中图片的原始图片
    previewImageView.image = img;
    [picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissModalViewControllerAnimated:YES];
}
posted @ 2012-11-14 18:04  白条围巾  阅读(358)  评论(0编辑  收藏  举报