同一个XIB中的多个视图。旋转视图和更改视图时出现问题

时间:2012-06-22 11:30:50

标签: iphone xcode uiview rotation

我有一个问题。 我的viewController的Xib有多个UIView。 应用程序以纵向模式启动,我可以将其旋转为横向。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES; // (interfaceOrientation == UIInterfaceOrientationPortrait);

}

当我处于横向模式并按下UIButton更改视图时,“新”视图仍保留在纵向模式下。 这是改变视图的代码:

-(IBAction) gotogame
{
     self.view = gameView;
}

我希望在更改视图时看到正确的旋转视图 怎么办呢?

2 个答案:

答案 0 :(得分:0)

将此行添加到您的方法

-(IBAction) gotogame
{
     self.view = gameView;
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:YES];
}

答案 1 :(得分:0)

我尝试了这个,它对我有用:

UIView *newView = [[UIView alloc] init];
newView.backgroundColor = [UIColor grayColor];
newView.frame = self.view.bounds;
[self.view addSubview:newView];