0

我有一个 TabBar 应用程序,我希望它是横向和纵向的。问题是当我转到选项卡 2 从我的表中进行选择然后选择选项卡 1 并旋转设备,然后再次选择选项卡 2 时,内容不知道设备已旋转并且不会正确显示我的自定义定向内容。我正在尝试编写一个私有方法来告诉视图它当前所处的方向。在 viewDidLoad 中我假设它是纵向的,但在 shouldAutoRotate 中我让它在私有方法中查找内容的正确对齐方式。请帮忙!!这是我的代码:

#import "DetailViewController.h"
#import "ScheduleTableViewController.h"
#import "BrightcoveDemoAppDelegate.h"
#import "Constants.h"

@implementation DetailViewController


@synthesize CurrentLevel, CurrentTitle, tableDataSource,logoName,showDescription,showDescriptionInfo,showTime, showTimeInfo, tableBG;

- (void)layoutSubviews {

 showLogo.frame = CGRectMake(40, 20, 187, 101);
 showDescription.frame = CGRectMake(85, 140, 330, 65);
 showTime.frame = CGRectMake(130, 10, 149, 119);
 tableBG.frame = CGRectMake(0, 0, 480, 320);

}

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
 self.navigationItem.title = CurrentTitle; 
 [showDescription setEditable:NO];
 //show the description
 showDescription.text = showDescriptionInfo;
 showTime.text = showTimeInfo;
 NSString *Path = [[NSBundle mainBundle] bundlePath];
 NSString *ImagePath = [Path stringByAppendingPathComponent:logoName];
 UIImage *tempImg = [[UIImage alloc] initWithContentsOfFile:ImagePath];
 [showLogo setImage:tempImg];
 [tempImg release];
 [self masterView];

}

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

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
 isLandscape = UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
 if(isLandscape = YES){
 [self layoutSubviews];

 }

}





- (void)didReceiveMemoryWarning {
 // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

 // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
 // Release any retained subviews of the main view.
 // e.g. self.myOutlet = nil;
}


- (void)dealloc {
 [logoName release];
 [showLogo release];
 [showDescription release];
 [showDescriptionInfo release];
    [super dealloc];
}


@end
4

1 回答 1

0

我相信您需要将-shouldAutorotateToInterfaceOrientation:方法传递给每个视图控制器。你可以在你的UITabBarController

- ( BOOL )shouldAutorotateToInterfaceOrientation:( UIInterfaceOrientation )
          interfaceOrientation
{
    for ( UIViewController *viewController in [ self viewControllers ])
        [ viewController
           shouldAutorotateToInterfaceOrientation:interfaceOrientation ];

    return YES;
}
于 2010-04-08T15:09:37.913 回答