开发者

XCode Redraw portrait layout with double high status bar

I'm having this issue with several screens in my app, but I'll explain what happens to my home screen. Hopefully the solution isn't as complicated as I'm thinking it will be. So my home screen has a logo at 开发者_运维技巧the top, a label(title) under that, 3 horizontal buttons under that, and finally, settings and info buttons in the bottom left and right hand corner respectively when if portrait orientation. In order to allow for landscape orientation, resizing masks were not able to achieve the look I wanted so I implemented the

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

method with an if and else statement, the "if" uses CGRectMakes to draw all of the elements where they should go in landscape layout, and the "else" redraws them back to their original places when changed back to portrait landscape. This all works very nicely. I remembered that we had to be able to handle the double high status bar, so I simulated it to see what it would do to my app. When I am on the home screen and toggle it on and off, the autoresizing of the items(which are set to adjust according to the top of the view) work nicely, by slightly squishing everything down a bit, and not hiding anything. I can toggle it off and on with no problems.

Now here's the problem:

When I have the double high status bar toggled on while on a different screen, then go back to my home screen, the resizing doesn't happen, and it redraws my screen full size according to the coordinates and sizes I have in the method I mentioned earlier, so the settings and info button are drawn halfway off the bottom of the screen. Same happens when switching from landscape back to portrait on the homescreen with the double high status bar already on.

Similarly, I have a map between a nav and tab bar on another page. When already on the page, and toggling it on and off, everything resizes nicely(the frame of the map changes height and the nav bar moves down). But again, I have a problem when switching to that screen from a different screen or from the landscape orientation, because instead of autoresizing appropriately, the map view and nav bar get pushed down behind the tab bar partially, obscuring the google trademark which is grounds for app rejection.

Sorry for the longwindedness, but I wanted to clearly describe what circumstances cause this problem. Any ideas would be greatly appreciated as I don't really have any idea how to approach this.


I've been trying to track down this problem myself. I think this happens because the autoresizing mask is only used when views are resized, and not when a new view is added to the scene.

For me, I wanted a settings view loaded from a nib and added on top of everything else. If the double-height bar was in effect when the view was added it would run off the bottom of the screen. To fix it you have to set the size and position of the view yourself when you load it. This is the code behind my working 'goto settings' button:

- (IBAction) settingsPressed:(id)_sender
{
    NSArray* a = [[NSBundle mainBundle] loadNibNamed:@"SettingsView" owner:self options:nil];
    SettingsView* settings = [a objectAtIndex:0];
    settings.frame = self.view.bounds;
    [[self view] addSubview:settings];
}

The important line being:

settings.frame = self.view.bounds;

Which, it would appear, classifies as a 'resize' and so the resizing-mask rules apply. I later added animations for the transition and it continues to work just fine.

Note: This method was in a View Controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜