第一个UIView纵向和第二个横向
我有一个应用程序,它有2个视图控制器。第一个viewcontroller应该是肖像,这是可以的,但是当我加载第二个视图控制器时,我无法使应用程序方向为风景...问题与iOS 6.第一个UIView纵向和第二个横向
我已经尝试了一切我在SO上找到了。
使用上viewWillAppear
和viewDidLoad
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
,
也:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
} else {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
}
-(BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeRight;
}
在2nd View Controller's
viewDidLoad
方法transform
view
添加这些代码到landscape
:
[self rotateController:self degrees:-90];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
//set it according to 3.5 and 4.0 inch screen in landscape mode
[self.view setBounds:CGRectMake(0, 0, 480, 320)];
添加rotateController
方法:
-(void) rotateController:(UIViewController *)controller degrees:(NSInteger)aDgrees
{
UIScreen *screen = [UIScreen mainScreen];
if(aDgrees>0)
controller.view.bounds = CGRectMake(0, 0, screen.bounds.size.height, screen.bounds.size.width);
else
{
controller.view.bounds = CGRectMake(0, 0, screen.bounds.size.width, screen.bounds.size.height);
}
controller.view.transform = CGAffineTransformConcat(controller.view.transform, CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(aDgrees)));
}
现将viewWillDisappear's
方法改为transform
view
改为protrait
。添加这些:
[self rotateController:self degrees:90];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
//set it according to 3.5 and 4.0 inch screen in protrait mode
[self.view setBounds:CGRectMake(0, 0, 320, 480)];
而且你orientation
方法应该是这样的,如果没有添加添加这些:
- (BOOL)shouldAutorotate
{
//make view landscape on start
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
编辑:添加这些macro
为radian
#define DEGREES_TO_RADIANS(angle) ((angle)/180.0 * M_PI)
你可能要解决您的方向 代码,下面这个观点控制器上添加以下代码
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
{
return UIInterfaceOrientationMaskPortrait;
}
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
{
return (toInterfaceOrientation==UIInterfaceOrientationPortrait);
}
}
和第二个视图控制器你可能想旋转所有的方向,然后没有必要添加任何代码ios6将自动管理方向。
也试过这个转到您的项目设置的摘要部分并禁用支持的界面方向。 – Jitendra 2013-05-06 04:51:20
您需要在应用程序摘要 - >部署信息中选择横向模式。
此外,如果你正在使用XIB文件来设计的UI,你需要第二个视图控制器方向设置为横向
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(BOOL)shouldAutorotate
{
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
-(NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
你没有回复我在方法shouldAutorotate
中,用这个替换你现有的代码。 希望它能帮助你。
在iOS 6之前,即在iOS 5和更早版本中,应用程序和视图控制器的旋转由各个视图控制器控制,而在iOS 6和更高版本中,负责旋转的视图控制器是容器Viewcontrollers,例如UINavigationController & UITabBarController 。你在项目中使用什么作为rootviewcontroller?
自转显然这里解释在这个后 Autorotation in iOS
你试试我的答案在[这里] [1]:http://stackoverflow.com/questions/15110838/xcode-how-但是仍然允许一个视图/ 15112927#15112927 – Ushan87 2013-05-06 05:03:32