与Three20非常奇怪的iOS方向问题

时间:2012-04-27 20:56:32

标签: ios interface-builder orientation three20

这是我见过的iOS开发中最奇怪的问题之一。我对iOS开发比较陌生,所以如果我遗漏了一些明显的东西或者我的术语不完全正确,我会道歉。如果您需要澄清,请在评论中告诉我,我会相应地编辑我的问题。

问题

我正在使用Three20,所以这可能与它有关。但我有一个“主视图”,它基本上是一系列链接到其他视图的图像(如下图所示)。如果我从纵向视图开始,一切都很好。

enter image description here

下一个视图是一个表格视图,如下所示:

enter image description here

YAY!我可以旋转,一切都与世界是对的。 但是如果我回到那个家庭视图,旋转到风景,然后转到这个桌面视图,世界就会破碎。

enter image description here

你会看到我的桌子右侧有一个随机空间。我不知道它来自何处以及如何来自。这是我的Controller.m文件:

#import "FriendTabsController.h"
#import "MyAppApp.h"
#import "JohnDoeManager.h"

@implementation FriendTabsController

@synthesize innerView, segmentedControl, innerController, friendsController, friendRequestsController;

- (void)addBottomGutter:(UIViewController*)controller {
  if ([controller isKindOfClass:[TTTableViewController class]]) {
    TTTableViewController* tableViewController = (TTTableViewController*)controller;
    tableViewController.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0,0,50+44,0);
    tableViewController.tableView.contentInset = UIEdgeInsetsMake(0,0,50+44,0);
  }
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {    
    return YES;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
  [super viewDidLoad];

  self.title = @"Friends";
  self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
  self.navigationController.navigationBar.tintColor = nil;


  friendsController = [[FriendsController alloc] init];
  friendRequestsController = [[FriendsController alloc] init];
  ((FriendsController*)friendRequestsController).friendRequests = YES;

  [self addBottomGutter:friendsController];
  [self addBottomGutter:friendRequestsController];

  innerController = friendsController;
  [innerView addSubview:innerController.view];
  [innerController viewDidLoad];

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    [self loadBannerAd:(orientation)];

}
-(void) loadBannerAd:(UIInterfaceOrientation)orientation{ 

  MainLayer *mi = [MainLayer getInstance];
    if (mi.useJohnDoeAds) {
    [[JohnDoeManager sharedInstance] setCurrentViewController:self];
    [mi.JohnDoeBanner.view removeFromSuperview];

        if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
            // This is a portait ad
            if ([[MyAppUtils getCurrentDevice] isEqualToString:@"iphone"]) {
                [mi.JohnDoeBanner setFrame:CGRectMake(0, 410-44, 320, 50)];
            }else{
                [mi.JohnDoeBanner setFrame:CGRectMake(0, 1024-44-90-20, 768, 90)];
            }                
        } else {
            // Landscape
            if ([[MyAppUtils getCurrentDevice] isEqualToString:@"iphone"]) {
                [mi.JohnDoeBanner setFrame:CGRectMake(0, 320-44-58, 410, 50)];
            }else{
                [mi.JohnDoeBanner setFrame:CGRectMake((1024-768)/2, 768-44-90-20, 768, 90)];
            }              
        }

        [self.view addSubview:mi.JohnDoeBanner.view];
          [mi.JohnDoeBanner rollOver];           
  }
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self loadBannerAd:(toInterfaceOrientation)];
}


- (IBAction)didChangeSegment:(UISegmentedControl *)control {
  if (innerController) {
    [innerController viewWillDisappear:NO];
    [innerController.view removeFromSuperview];
    [innerController viewDidDisappear:NO];
  }

  switch (control.selectedSegmentIndex) {
    case 0:
      innerController = friendsController;
      self.title = @"Friends";

      break;
    case 1:
      innerController = friendRequestsController;
      self.title = @"Requests";

      break;
  }
  [innerController viewWillAppear:NO];
  [innerView addSubview:innerController.view];
  [innerController viewDidAppear:NO]; 
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [innerController viewWillAppear:animated];
  self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
  self.navigationController.navigationBar.tintColor = nil;
}

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  [innerController viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
  [innerController viewWillDisappear:animated];
  [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated {
  [innerController viewDidDisappear:animated];
  [super viewDidDisappear:animated];
}

- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
  [friendsController release], friendsController = nil;
  [friendRequestsController release], friendRequestsController = nil;
  [super viewDidUnload];
}

- (void)dealloc {
  [super dealloc];
}


@end

有人可以告诉我发生了什么事吗?帮助!

1 个答案:

答案 0 :(得分:2)

您需要将wantsFullScreenLayout属性设置为YES。

在你的init方法集

self.wantsFullScreenLayout = YES;

这将解决您的问题。