【问题标题】:How do I rotate from landscape to portrait upon loading a view?加载视图时如何从横向旋转到纵向?
【发布时间】:2010-03-10 21:28:51
【问题描述】:

我正在为一个项目开发一个模块,当我得到它时屏幕处于横向模式。我必须加载一个新视图,然后切换到纵向模式。虽然这看起来很简单,但我还没有找到一个简单的解决方案。这是我尝试过的:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
locationsView =[[LocationsViewController alloc] initWithNibName:@"LocationsViewController" bundle:nil];
[self.view addSubview:locationsView.view];

这并没有像我需要的那样工作。它将状态栏旋转到纵向模式,而不是视图的其余部分。

有什么建议吗?

托马斯

【问题讨论】:

    标签: objective-c iphone


    【解决方案1】:

    做到了:

    [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait];
    self.view.transform = CGAffineTransformIdentity;
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
        //resize the view
    self.view.bounds = CGRectMake(0.0, 0.0, 320, 460);
    self.view.center = CGPointMake(240, 140);
    
    locationsView =[[LocationsViewController alloc] initWithNibName:@"LocationsViewController" bundle:nil];
    [self.view addSubview:locationsView.view];
    

    并确保 degreeToRadian 在 global.h 中定义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 2015-10-25
      • 1970-01-01
      • 2011-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多