Search code examples
iphoneuitabbaruiviewanimation

UIView has gap on top after animating


I have a tabbarview application that has a button in one of the tabs. When Pressing that button, something will happen, and the user will be switched to another tab.

I made an animation in that button:

UIView * fromView = self.tabBarController.selectedViewController.view;
UIView * toView = [[self.tabBarController.viewControllers objectAtIndex:0] view];
[UIView transitionFromView:fromView 
                    toView:toView 
                  duration:0.6 
                   options:(UIViewAnimationOptionTransitionCurlDown)
                completion:^(BOOL finished) {
                    if (finished) {
                        self.tabBarController.selectedIndex = 0;
                    }
                }];

Which I got from here. However the problem is that after animating, I seem to have a gap on the top of the screen that is about as high as the status bar. Does anyone know what's causing this? This gap quickly closes when the animation finishes (which is when we do self.tabBarController.selectedIndex = 0

Sorry I had to hide some details

By the way, the problem still persist if I swap the animation to something else or even without animation.

Additional info, here's the frame details:

from frame: x:0.000000, y:0.000000, w:320.000000, h:411.000000
to frame: x:0.000000, y:0.000000, w:320.000000, h:431.000000

Solution

  • I've found a very hacky way to do it:

    CGRect to = fromView.superview.frame;
    to.origin.y -= 20;
    fromView.superview.frame = to;
    

    Anyone that can explain to me why I had to do this and a more elegant way to do this will get the answer accepted.