2012-06-14 42 views
0

我想强制我的视图去风景,只是当我打电话的方法。IOS - 如何强制视图到风景

当我的方法运行我打电话:

[self shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)UIInterfaceOrientationLandscapeRight]; 

方法自转

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation); 
} 

的问题是,认为不要用力旋转。是可以在模拟器上测试它,或只是在真实的设备中工作?

回答

1
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES]; 
+0

泰克斯很多人!你钉了它! = D – 88fsantos

+0

我有一个问题。我在里面创建的视图没有设置为横向:S现在它应该有480宽度和320高度,对吧?但它不:S – 88fsantos

+1

这听起来像你需要创建一个相对大小的视图。因此,不要使用'initWithFrame:CGRectMake(0,0,320,480)]'创建一个视图,请尝试像'initWithFrame:CGRectMake(0,0,[UIScreen mainScreen] .bounds.size.width,[UIScreen mainScreen] .bounds.size.height])' – Anthony