iPhone 设备方向问题

发布于 2024-10-16 08:39:01 字数 2047 浏览 5 评论 0原文

我的应用程序是基于导航的。

除报告模式外,所有视图均显示纵向模式。当设备横向旋转时,报告模式显示横向模式。

如果设备处于旋转横向模式,则报表视图将显示横向模式。如果报表处于横向模式,则再次在设备纵向模式下旋转,它将显示当前视图的正常视图。

我的视图显示当前操作的流程。 从当前视图来看是纵向模式,我在横向模式下旋转设备,因此获得报告模式的横向模式。仅旋转两次后,我就可以在纵向模式下获得当前视图。我需要减少拖车旋转。请指导我。如果再次旋转我需要以纵向模式显示当前视图,如何检查报告横向模式后的条件。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏日浅笑〃 2024-10-23 08:39:01

我不确定我是否理解你的问题,但代码看起来逻辑可能颠倒了。
在ReportViewController中,

- (BOOL)shouldAutorotateToInterfaceOrientation

在旋转之前调用,所以它应该
对于纵向返回 YES(是,允许视图从横向旋转到纵向)
并为 Landscape 返回 NO(NO,不允许视图从 Landscape 旋转到 Landscape)。

在 CurrentVC 中也类似 - 尝试

return (interfaceOriention==UIInterfaceOrientationLandscape);

希望有帮助。
-麦克风

I'm not sure I understand your question, but the code looks like it might have the logic reversed.
In the ReportViewController,

- (BOOL)shouldAutorotateToInterfaceOrientation

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

return (interfaceOriention==UIInterfaceOrientationLandscape);

Hope that helps.
-Mike

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文