开发者

Views have wrong position and size in landscape mode

I'm developing "landscape mode-only" app for an iPad. Problem is that my views have wrong positions on the screen, and I can't find the reason...

I've set necessary properties in the Info.plist:

    <key>UIInterfaceOrientation</key>
    <string>UIInterfaceOrientationLandscapeRight</string>

    <key>UISupportedInterfaceOrientations</key>
    <array>
       <string>UIInterfaceOrientationLandscapeLeft</string>
       <string>UIInterfaceOrientationLandscapeRight</string>

I have hierarchy like that:

UIWindow --> MainMenuViewController.view --> MyTableviewController.view

In AppDelegate's application:didFinishLaunchingWithOptions: method I have this code: CGRect rect = [[UIScreen mainScreen] bounds]; [window setBounds:rect];

mainMenuController = [[MainMenuViewController alloc] init];

[window addSubview:mainMenuController.view];
[window makeKeyAndVisible];

return YES;

In MyMenuController's viewDidload: I have that:

[super viewDidLoad];
[[UIApplication sharedApplication] setStatusBarHidden:YES];

SelectPictureTableViewController *selectPictureViewController = [[SelectPictureTableViewController alloc] initWithStyle:UITableViewStylePlain];
[selectPictureViewController.view setBounds:CGRectMake(0.0, 128.0, 1024.0, 640.0)];
[self.view addSubview:selectPictureViewController.view]; 

In SelectPictureTableViewController's initWithStyle: I wrote that:

if ((self = [super initWithStyle:style])) {
    templatesArray = [[NSMutableArray alloc] init];
    tumbnailsInRow = 3;

    self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.allowsSelection = NO;
}
return self;

In both ViewControllers I have this implementation:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortrait && 
 interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

For me it looks like it should display 1024x640 table view. But it displays tableview with height about 350px and shifted to the middle of the screen (about 250px from the top). Do you have any ideas why it can be so shifted? Probably I have to set up bounds somewhere and forgot to do that? Stucked with this problem for few hours.

PS: Without MainMenuViewController position of the tableview was fine (when I added tableview as subView of the UIWindow). But I need to place other UI elements to the scre开发者_开发问答en and I need this MainMenuViewController...

Cheers!


I found the answer:

I've added that to my MainMenuViewController's method viewDidLoad:

    UIViewAutoresizing mask = (1 & !UIViewAutoresizingFlexibleTopMargin);
    selectPictureViewController.view.autoresizingMask = mask;

Problem was a default autoresizingMask.


You set the bounds of the TableView. Does this also work? I would try to set the frame. Like this:

selectPictureViewController.view setFrame:CGRectMake(0,0,1024,640)];

But I don't know if it works. It just looks strange for me if you use setBounds...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜