iphone - iOS : How can I rotate a view control when another view segues to it?

标签 iphone xcode rotation autorotate

我正在制作一个应用程序只是为了好玩,它似乎工作正常,除了当我希望它只在一个屏幕上横向显示时,它会保持纵向。我怎样才能让它在加载时自动旋转到横向? 我已经尝试过这个:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);   
}

但是这似乎不起作用。仅当我旋转设备时,它才会旋转 View ,然后它将保持横向状态,但我希望它能够在加载后立即执行操作,而无需用户旋转设备以使其脱离纵向状态。我有什么遗漏的吗?感谢您提供的所有帮助!如果您想从该应用程序中获取更多代码,我将非常乐意与您分享。

最佳答案

在 viewDidLoad 方法和 shouldautorotate 方法中添加此内容:

 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
 [[self view] setBounds:CGRectMake(0, 0, 480, 320)];
 [[self view] setCenter:CGPointMake(160, 240)];
 [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];

关于iphone - iOS : How can I rotate a view control when another view segues to it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11076113/

相关文章:

html - CSS3 Transform rotate 改变流

python - 如何在 tkinter Canvas 中旋转椭圆?

javascript - jquery ui 可在旋转的 div 中拖动

ios - xcode 4.6问题/metaio配置中的“文件所有者”

ios - 圆形功能无法按预期工作

ios - 如何在 Xcode 中将商品添加到 Outlet Collection

ios - Xcode 中单个场景中的多个自定义 View

objective-c - 在 ARC 中保留循环

iphone - Mobile Safari 浏览器 - 视口(viewport)问题

iphone - 在不更改任何代码的情况下将 iPhone 应用程序提交为通用是否有效?