Note that there are some explanatory texts on larger screens.

plurals
  1. POBuild a tabbar view controller from scratch
    primarykey
    data
    text
    <p>Apple's tab bar controller has a lot of limitations. One important limitation is that you can't modify the tab bar in a rejection safe mode. My tab bar has a simple sliding movements and it's multi row. For those reasons I decided to build a TBVC from the beginning; everything seems to work correctly, but I'm really messing around with rotation. Every time that I change orientation main view frames are changed.</p> <p>Here is my hierarchy from top to the container view: -MainView--contains-->TabBarView+containerView The containerView is the view used to contain views loaded from the other controllers. Here is the -loadView method of my CustomTabBaViewController</p> <pre><code>- (void)loadView { UIView *theView=[[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; theView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; theView.backgroundColor=[UIColor greenColor]; containerOfControllersView=[[UIView alloc] initWithFrame:theView.bounds]; containerOfControllersView.backgroundColor=[UIColor blueColor]; containerOfControllersView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; [theView addSubview:containerOfControllersView]; ideoloTabBar=[[IdeoloTabBar alloc]initWithNumberOfControllers:[controllers count]]; [theView addSubview:ideoloTabBar]; self.view=theView; [theView release]; } </code></pre> <p>When I set a new view from another controller I use this method:</p> <pre><code>-(void)setCurrentViewWithView:(UIView*)theView{ if ([[self.containerOfControllersView subviews] count]&gt;0) { UIView *tagView=[self.containerOfControllersView viewWithTag:555]; tagView.tag=0; [tagView removeFromSuperview]; } theView.tag=555; theView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; theView.frame=[[UIScreen mainScreen]applicationFrame]; [self.containerOfControllersView addSubview:theView]; [self.view bringSubviewToFront:ideoloTabBar]; } </code></pre> <p>As you can see the views from other view controllers are applied using the applicationFrame.</p> <p>When I rotate the device happens something wrong, the mainview not only is resized according to the new orientation but also moved by 20px (status bar size) to the botton, thus leaving a gap between the status bar and the container view. Since I gave the mainview the screen bounds I can't understand with it should be moved.</p> <p><strong>UPDATE</strong></p> <p>I'm trying a different approach so I've modified the loadView like that:</p> <pre><code>- (void)loadView { [super loadView]; containerOfControllersView=[[UIView alloc] initWithFrame:self.view.bounds]; containerOfControllersView.backgroundColor=[UIColor blueColor]; containerOfControllersView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; self.view.backgroundColor=[UIColor greenColor]; [self.view addSubview:containerOfControllersView]; ideoloTabBar=[[IdeoloTabBar alloc]initWithNumberOfControllers:[controllers count]]; [self.view addSubview:ideoloTabBar]; } </code></pre> <p>And in the setCurrentViewWithView:(UIView*)theView I've modified the line with</p> <pre><code>theView.frame=self.view.bounds; </code></pre> <p>instead of using the applicationFrame.</p> <h3>NOW:</h3> <p>On iPhone when I try to load a modalView it cuts about 40px at the bottom On iPad when I try to load a modalView it lefts 20px at the bottom, because 20px are under the status bar but wantsFullScreen is NO.</p> <h3>UPDATE 2</h3> <p>It seems that the presentModalViewController should be called from the root view controller. I will create a protocol and an abstract UIViewController subclass to implement it an load it correctly.</p> <p>Any suggestion? work around?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload