ios - 如何在另一个 View 中打开图像?

标签 ios objective-c image uiimagepickercontroller

我正在尝试制作一个具有 2 个 View 的 iOS 应用程序。第一个 View 包含两个按钮:相机和库。当我选择“库”时,我访问相机胶卷。我想选择一张照片并在另一个 View 中打开它。到目前为止我写了这个函数

-(IBAction) getPhoto:(id) sender {
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if((UIButton *) sender == choosePhotoBtn) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    } else {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }

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

}   


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion: Nil];
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

在同一 View 中打开我的图像。如何在其他 View 中打开此图像?

最佳答案

你可以做类似的事情

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [picker dismissViewControllerAnimated:YES completion:^{
        YourSeconViewController *svc = [[UIViewController alloc] initWithNibName:@"YourSeconViewController" bundle:nil];
        svc.imageView.Image = image;
        [self presentViewController:svc animated:YES completion:nil];
    }];
}

关于ios - 如何在另一个 View 中打开图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14524058/

相关文章:

ios - 应用程序崩溃并显示 <gap :config-file platform ="ios" parent ="NSLocationAlwaysUsageDescription" overwrite ="false"> in config. xml

c# - 正在保存图像,GDI+ 中出现一般性错误

ios - 如何创建多 ImageView 设计?

ios - 如何将数据加载到 ios 中自定义 tableview 单元格内的选择器 View ,objective c

image - 如何在 SVG 中控制从两个图像创建的图像蒙版输出的不透明度?

C# 将 System.Drawing.Image 附加到电子邮件

ios - Json Swift 2 不输入 for

objective-c - 将图片从 assets-library 复制到 app 文件夹

ios - 奇怪的 UITableView 崩溃 : NSRangeException

ios - 将 View Controller 连接到委托(delegate)类 - CLLocationManager/iOS8