0

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
Community
  • 1
  • 1
Enrico Susatyo
  • 19,372
  • 18
  • 95
  • 156

2 Answers2

0

The tab bar controller's area also covers the area underneath the status bar. So it's own client view has origin.y of 20.

Thus you need to set the incoming view frame correctly before invoking the transition.

Cocoanetics
  • 8,171
  • 2
  • 30
  • 57
  • Try to Override or KVO the setFrame of this view and inspect which code is setting the frame back to origin 20. Maybe it's your own code. – Cocoanetics Jun 20 '11 at 05:51
  • both of the views starts from (0,0), but the second view has height of 431 as oppose of 411 for the first view. I'm guessing this may be the problem, but since both of them starts from (0,0) wouldn't the position be the same? – Enrico Susatyo Jun 20 '11 at 06:08
  • it depends on what view they are mounted on. The frame coordinates are in the coordinate system of the superview. – Cocoanetics Jun 20 '11 at 06:15
  • Ok, I've basically shifted the superview frame by 20 pixels up. But this is a very bad way to do it, I think. Do you know why it happened? – Enrico Susatyo Jun 20 '11 at 07:15
  • I think that the table view controller has a view that it controls and sets the coordinates for. Your animation must be confusing it. It's not meant to be used like this. – Cocoanetics Jun 20 '11 at 10:02
  • What's a better way to do it, do you have any idea? – Enrico Susatyo Jun 20 '11 at 10:57
0

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.

Enrico Susatyo
  • 19,372
  • 18
  • 95
  • 156