简体   繁体   English

在后台呈现视图控制器

[英]Present a view controller in the background

I am having a problem with presenting a view controller while another one is already presented. 我在呈现视图控制器时遇到问题,而另一个已经呈现。

In my app, I present a UIImagePickerController , which after selecting an image (either from the library or through the device's camera) should return to another view controller. 在我的应用程序中,我提出了一个UIImagePickerController ,它在选择一个图像(从库或通过设备的相机)后应返回到另一个视图控制器。

For example, let's say you clicked a camera button which launches the camera, and after you take a picture, the camera slides down, but the view you see is not the one with the camera button but a view which lets you edit the metadata of the image. 例如,假设您单击了一个启动摄像头的摄像头按钮,拍照后摄像头向下滑动,但您看到的视图不是带摄像头按钮的视图,而是一个可以编辑元数据的视图。图片。

Does anyone know a way to accomplish this task? 有谁知道完成这项任务的方法?

Thanks ahead, iLyrical. 谢谢你,iLyrical。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    [picker dismissModalViewControllerAnimated:NO];

    NewViewController *viewController = [[NewViewController alloc] init];
    viewController.image = image;
    [self presentModalViewController:viewController animated:NO];
}

And if you can use iOS 5.0 or newer: 如果您可以使用iOS 5.0或更高版本:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
   [picker dismissViewControllerAnimated:YES completion:^(){
        NewViewController *viewController = [[NewViewController alloc] init];
        viewController.image = image;
        [self presentViewController:viewController animated:NO completion:nil];
    }];
}

Check Apple's doc on UIViewController Class Reference UIViewController类参考上查看Apple的文档

If you are able to initialize the final viewController before presenting UIImagePickerController, you can try: 如果您能够在呈现UIImagePickerController之前初始化最终的viewController,您可以尝试:

  1. Initialize final viewController 初始化最终的viewController
  2. Set it hidden or its view's alpha=0 and push non-animated 将其设置为隐藏或其视图的alpha = 0并推送非动画
  3. Present imagePicker viewController 目前imagePicker viewController
  4. Set the final viewController non-hidden 设置最终的viewController非隐藏
  5. Dismiss modal viewController 关闭模态viewController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM