简体   繁体   English

iPhone设备方向问题

[英]iPhone device orientation problem

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

}

I'm not sure I understand your question, but the code looks like it might have the logic reversed. 我不确定我是否理解您的问题,但是代码看起来好像逻辑相反。 In the ReportViewController, 在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 同样在CurrentVC中-试试

return (interfaceOriention==UIInterfaceOrientationLandscape);

Hope that helps. 希望能有所帮助。 -Mike -麦克风

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM