iPhone 设备方向问题
我的应用程序是基于导航的。
除报告模式外,所有视图均显示纵向模式。当设备横向旋转时,报告模式显示横向模式。
如果设备处于旋转横向模式,则报表视图将显示横向模式。如果报表处于横向模式,则再次在设备纵向模式下旋转,它将显示当前视图的正常视图。
我的视图显示当前操作的流程。 从当前视图来看是纵向模式,我在横向模式下旋转设备,因此获得报告模式的横向模式。仅旋转两次后,我就可以在纵向模式下获得当前视图。我需要减少拖车旋转。请指导我。如果再次旋转我需要以纵向模式显示当前视图,如何检查报告横向模式后的条件。
Here at ReportViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
@interface CurrentViewController
BOOL isShowingLandscapeView;
Report *landscapeViewController;
@implementation CurrentViewController
- (void)viewDidLoad
{
[super viewDidLoad];
Report *viewController = [[Report alloc]initWithNibName:@"Report" bundle:nil];
self.landscapeViewController = viewController;
[viewController release];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
[self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController:self.landscapeViewController animated:YES];
isShowingLandscapeView = YES;
}
else if(deviceOrientation == UIInterfaceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait ); // support only portrait
}
My application is Navigation based.
All views are displaying Portrait mode except Report mode.Report mode display landscape mode when device is rotate landscape.
If device is rotate landscape mode Report view is displaying landscape mode.if report is landscape mode once again rotate in device Portrait mode it will display normal view of current view.
Flow of current action my view display.
From current view is Portrait mode and i am rotating device in landscape mode so getting Landscape mode of Report mode. after two rotate only i am getting current view in Portrait mode. I need to reduce tow rotation . please guide me . How to check condition for after landscape mode of Report if once again rotate i need to display current view in Portrait mode.
Here at ReportViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
@interface CurrentViewController
BOOL isShowingLandscapeView;
Report *landscapeViewController;
@implementation CurrentViewController
- (void)viewDidLoad
{
[super viewDidLoad];
Report *viewController = [[Report alloc]initWithNibName:@"Report" bundle:nil];
self.landscapeViewController = viewController;
[viewController release];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
[self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController:self.landscapeViewController animated:YES];
isShowingLandscapeView = YES;
}
else if(deviceOrientation == UIInterfaceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait ); // support only portrait
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否理解你的问题,但代码看起来逻辑可能颠倒了。
在ReportViewController中,
在旋转之前调用,所以它应该
对于纵向返回 YES(是,允许视图从横向旋转到纵向)
并为 Landscape 返回 NO(NO,不允许视图从 Landscape 旋转到 Landscape)。
在 CurrentVC 中也类似 - 尝试
希望有帮助。
-麦克风
I'm not sure I understand your question, but the code looks like it might have the logic reversed.
In the ReportViewController,
is called before the rotation, so it should
return YES for Portrait (YES, allow the view to rotate from Landscape TO portrait)
and return NO for Landscape (NO, do not allow the view to rotate to Landscape from Landscape).
And similarly in CurrentVC - try
Hope that helps.
-Mike