Search code examples
iosobjective-ciphoneuianimation

UI Screen becomes black after UIAnimation


My problem is... I have the object of parent view controller and i wanted to animate second view controller over that. So i added a subview called backgroundview over the view of parentvc.view and then the view which needs to be drawn over the backgroundView. But after animation completes for a second, i can see the views the way i want them to be but then it is replaced by a complete black screen.

I think my topmost view is redrawn so how do i rectify this issue.

Code :-

- (void)viewDidLoad {
    [super viewDidLoad];

    //_colorCaptureOptions = [NSArray arrayWithObjects: @"Camera", @"Color Slider / Color Wheel", nil];

    mExtractionQueue = [[NSOperationQueue alloc] init];
    [mExtractionQueue setMaxConcurrentOperationCount:1];


    CGRect screenRect = [[UIScreen mainScreen] bounds];

    //CGRect screenRect = self.view.frame;

    self.backgroundView = [[UIView alloc] initWithFrame:screenRect];
    self.backgroundView.backgroundColor = [UIColor clearColor];

    [self.parentVC addChildViewController:self];
    [self.parentVC.view addSubview:self.backgroundView];
    //[self didMoveToParentViewController:self.parentVC];

    UITapGestureRecognizer *guideTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleScrimSelected)];

    [self.backgroundView addGestureRecognizer:guideTap];
    [self.backgroundView addSubview:self.view];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        CGRect screenRect = [[UIScreen mainScreen] bounds];

        CGFloat viewHeight = 150;

        self.backgroundView.alpha = 0.0;
        self.view.alpha = 1;
        self.view.frame = CGRectMake(0, screenRect.size.height, screenRect.size.width, viewHeight);


        [UIView animateWithDuration:0.2
                              delay:0
                            options: UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             self.backgroundView.alpha = 1.0;

                             self.view.frame = CGRectMake(0, screenRect.size.height - viewHeight, screenRect.size.width, viewHeight);
                         }
                         completion:^(BOOL _finished) {
        }];
    }
}

Solution

  • Well, for clarity you'd better to provide few screenshots.
    For all the rest:

    1. Possibly, your background view is simply black that leads to black screen. Or it even is [UIColor clearColor]

    2. better not use childViewController, it breaks MVC

    3. better not change frame inside animation directly

    4. If you want present another controller with animation, use this UIViewControllerTransitioningDelegate and this UIViewControllerAnimatedTransitioning in your objects, so do not reinvent transitions. Refer to this custom controller transition tutorial

    Hope this may help you

    EDIT: [UIColor clearColor] removes colour entirely, so that means you will have no color at all.

    The best solution for you now is rewrite those controllers, split up one from another, get rid of container for viewControllers, change animation to custom and than problem will disappear as a magic. If you solve you problem, do not forget to mark question as resolved, please