Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

ios - Problems dismissing and representing UIImagePickerController camera iOS8.4

EDIT Problem reinstated from scratch.

I have a ViewController A which has a Navigation Bar Button which presents an UIImagePickerController of sourcetype UIImagePickerControllerSourceTypeCamera, we'll call this ViewController B. In the didFinishPickingMediaWithInfo: method of A, I then present ViewController C.

The problem now starts here. When I finally reach C, we can see that view stack is clearly:

A -modal-> B -modal-> C

From C I then have a "Back" button present on the navigation bar which should take me back to B. However, since B is an UIImagePickerController, I cannot reuse it and it must be dismissed. So, to make this happen, I currently have the following method executing for that "Back" button on C:

- (IBAction)backOnPost:(UIBarButtonItem *)sender
{
    [self.view endEditing:YES];

    UINavigationController *LogControl = [self.storyboard instantiateViewControllerWithIdentifier:@"LogControl"];
    RGLogViewController *logView = (RGLogViewController *)LogControl.topViewController;

    [UIView animateWithDuration:0.25 animations:^{
         self.presentingViewController.view.alpha = 0;
        [self.presentingViewController dismissViewControllerAnimated:NO completion:nil];
        [self.presentingViewController.presentingViewController dismissViewControllerAnimated:NO completion:nil];
    } completion:^(BOOL finished){
        [logView setBoolBackPushed];
    }];
}

The above code works in that it takes me back to A by dismissing B and C. However, you can still see the transition because of a bit of "black-screening" from the dismissal of the two ViewControllers. You can see in the completion block [logView setBoolBackPushed];, this sets a static BOOL variable to true so that the beginning of A's viewWillAppear: presents a new UIImagePickerController immediately - the method looks like this:

- (void)viewWillAppear:(BOOL)animated
{
    NSLog(@"HERES postBackButtonPushed:%hhd", postBackButtonPushed);

    if(postBackButtonPushed == true)
    {
        self.view.hidden = YES;
        self.navigationController.navigationBar.hidden = YES;
        self.tabBarController.tabBar.hidden = YES;

        UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.delegate = self;
        [self presentViewController:imagePicker animated:NO completion:^{}];
    }

This is currently how I am getting the following desired effect: Go from A to the camera (B), to C and then back to a new camera which is our new B. This is achieved w/ almost perfect seamless transitions.

Im still having problems with being able to slightly see the transitions. Another problem is the timing. This collaboration of dismissing and presenting ViewControllers takes more time than I would like it to. It's almost instantaneous, but I would like something better. What should I do and am I doing something wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

there are some possible cases that cause your problem :

  1. presenting B after A and then presenting C is a bit strange behaviour for both UX/UI and by code. Either push B from A and then present C over B OR dismiss A, present B, dismiss B, present C.

  2. there are completion methods and you are not using them. your code show that you call dismissViewControllerAnimated twice for C and B for ex. you should handle presenting and dismissing order. I think iOS 8.2+ or 8.3+ start to handle them more efficiently. And if there is an error, it will crash after this version.

  3. imagepicker controller cause this error while dismissing VCs in different ways. For ex. showing alert popup before presenting a VC can cause also a crash.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...