【发布时间】:2010-01-18 13:17:08
【问题描述】:
我的 iPhone 应用程序是基于导航的,包含许多仅纵向视图和一个仅用于查看图像的横向视图。因此,即使设备处于纵向模式,我也想强制此仅横向视图自动旋转为横向。
这就是我在该视图的控制器中所做的:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
_originalTransform = [[appDelegate navigationController].view transform];
_originalBounds = [[appDelegate navigationController].view bounds];
_originalCenter = [[appDelegate navigationController].view center];
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +80.0, +100.0);
[[appDelegate navigationController].view setTransform:landscapeTransform];
[appDelegate navigationController].view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[appDelegate navigationController].view.bounds = CGRectMake(0.0, 0.0, 480.0, 320.0);
[appDelegate navigationController].view.center = CGPointMake (240.0, 160.0);
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}
}
- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
[self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[appDelegate navigationController].view setTransform:_originalTransform];
[[appDelegate navigationController].view setBounds:_originalBounds];
[[appDelegate navigationController].view setCenter:_originalCenter];
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
}
现在我的视图总是以横向模式显示。但是有一个问题。此视图定位不正确,如this screenshot 所示。
我尝试在旋转后手动设置框架,但没有帮助。此外,我没有找到完整的指南,如何将一个视图设置为仅限横向。 请帮我解决这个问题。
【问题讨论】:
标签: iphone landscape uinavigationitem