【问题标题】:iPhone device orientation problemiPhone设备方向问题
【发布时间】:2011-06-23 17:07:10
【问题描述】:

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

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

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

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

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

}

【问题讨论】:

    标签: iphone orientation device


    【解决方案1】:

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

    - (BOOL)shouldAutorotateToInterfaceOrientation
    

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

    在 CurrentVC 中也类似 - 尝试

    return (interfaceOriention==UIInterfaceOrientationLandscape);
    

    希望对您有所帮助。 -迈克

    【讨论】:

    • 无法返回(interfaceOriention==UIInterfaceOrientationLandscape);UIInterfaceOrientationLandscape没有检查条件。只有可能的左或右和岛景。 updateLandscapeView 方法当我检查纵向模式 if (UIDeviceOrientationIsPortrait(deviceOrientation) && !isShowingLandscapeView) 当前视图为纵向并旋转设备时,当前视图为横向并旋转,报告视图为横向并将当前视图旋转为纵向。我需要当前视图为纵向如果旋转设备报告视图是横向并且旋转当前视图是纵向。
    猜你喜欢
    • 2011-09-27
    • 2020-07-24
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多