iPhone开发viewcontroller纵向转横向不自动旋转

发布于 2024-11-17 05:45:09 字数 669 浏览 3 评论 0原文

我有一个视图控制器正在推动另一个应该处于横向模式的 vc,但在推动时它不会自动旋转到横向模式。仍然是肖像。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        return YES;
    }

    return NO;
}

当弹出 vc 并返回到第一个控制器时一切都很完美,它仅以纵向模式显示。

我可以通过旋转手机/模拟器来旋转第二个 vc,然后坚持自动旋转景观。然后弹出时也完美,返回纵向模式。

那么有没有什么方法可以将界面旋转为横向。曾尝试使用

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

但没有取得巨大成功。然后状态栏在弹出时停留在横向状态。

I have a viewcontroller that's pushing another vc that should be in landscape mode but it does not autorotate to landscape when pushed ie. still in portrait.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        return YES;
    }

    return NO;
}

When a popping the vc and back to the first controller all is perfect, it only displays in portrait mode only.

I can get the second vc to rotate by rotating the phone/emulator and then stick to the autorotate landscape. Then also perfect when popping, returns to portrait mode.

So is there any way to maybe progamaticly rotate the interface to landscape. Have tried using

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

But to no great success. Statusbar then stuck in landscape when popping.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吾家有女初长成 2024-11-24 05:45:09

在您的 viewDidLoad 方法中使用它,它应该可以工作

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI_2);
[self.view setTransform:rotate];

CGRect contentRect = CGRectMake(0, 0, 480, 320); 
self.view.frame = contentRect; 
[self.view setCenter:CGPointMake(160.0f, 240.0f)];

Use this in your viewDidLoad method, it should work

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI_2);
[self.view setTransform:rotate];

CGRect contentRect = CGRectMake(0, 0, 480, 320); 
self.view.frame = contentRect; 
[self.view setCenter:CGPointMake(160.0f, 240.0f)];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文