Iphone iOS:当另一个视图与视图控件相连时,如何旋转视图控件?
我正在做一个应用程序只是为了好玩,它似乎工作得很好,除了当我希望它只在一个屏幕上是横向的,它将保持纵向。如何使其在加载时自动旋转到横向? 我已经试过了:Iphone iOS:当另一个视图与视图控件相连时,如何旋转视图控件?,iphone,xcode,rotation,autorotate,Iphone,Xcode,Rotation,Autorotate,我正在做一个应用程序只是为了好玩,它似乎工作得很好,除了当我希望它只在一个屏幕上是横向的,它将保持纵向。如何使其在加载时自动旋转到横向? 我已经试过了: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ) || (inte
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
然而,这似乎不起作用。只有当我旋转设备时,它才会旋转视图,然后它将保持在横向视图中,但我希望它能够在加载后立即这样做,而用户无需旋转设备以使其脱离纵向视图。有什么我遗漏的吗?谢谢你的帮助!如果您想从应用程序中获得更多代码,我非常乐意与您分享。在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)];
试试这个代码
@interface UIViewController(ESUtils)
-(void)changeToPortrait;
@end
@implementation UIViewController(ESUtils)
-(void)changeToPortrait
{
//for will call a shouldAutorotateToInterfaceOrientation func
UIViewController *view = [[UIViewController alloc] init];
[self presentModalViewController:view animated:NO];
[self dismissModalViewControllerAnimated:NO];
[view release];
}
@end
你想做两件事 首先在interface builder上,转到您想要在land scape中显示的视图,并确保方向设置为“横向”(如果在推断中,则将采用父方向)。您可以在property inspector的第4个选项卡上的“模拟度量”下找到 其次,该视图必须包含您发布的代码