2011-07-05 6 views
0

보기 제어기 A는보기 제어기 B를 가로 방향으로 표시합니다.세로 회전 후 UIViewController가 가로 방향으로 멈춤

#pragma mark Rotation Delegate Methods 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations. 
    return YES; 
} 

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 
     [landscapeChartViewController.chartImageView reloadWithUrl: 
      [NSString stringWithFormat:@"someurl",[symbol uppercaseString]]]; 

     NSLog(@"showing chart"); 
     [self presentModalViewController:landscapeChartViewController animated:NO]; 
    }  
} 

이 경우 정상적으로 작동합니다. 보기 제어기 B는 가로 방향으로 나타납니다. 다음은보기 제어기 B의 구현입니다.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return YES; 
} 

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
     NSLog(@"dismissing chart"); 
     [self.parentViewController dismissModalViewControllerAnimated:NO]; 
    } 
} 

문제는 다시 세로보기로 표시 제어기 A를 표시 할 때,보기 제어기 A가 가로 방향으로 고정되어 있다는 것입니다. 이 문제를 어떻게 해결할 수 있습니까?

답변

0

편집 : 귀하의 코멘트를 읽은 후, 나는 다음과 같이 willAnimateRotationToInterfaceOrientation 대신 willRotateToInterfaceOrientation:duration:를 사용하려고 시도하는 것이 좋습니다 :

컨트롤러 A :

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 
    [landscapeChartViewController.chartImageView reloadWithUrl: 
     [NSString stringWithFormat:@"someurl",[symbol uppercaseString]]]; 

    NSLog(@"showing chart"); 
    [self presentModalViewController:landscapeChartViewController animated:NO]; 
    }  
} 

컨트롤러 B : 내가 할

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
     NSLog(@"dismissing chart"); 
     [self.parentViewController dismissModalViewControllerAnimated:NO]; 
    } 
} 

어느 정도는 내 프로젝트에서 동일하지만 두 가지 비 모달보기 사이에서만 가능합니다.

+0

당신은 제대로 내 문제를 이해합니다. 불행하게도,이 코드를 구현할 때 세로보기 모드로 회전 할 때보기 컨트롤러 B가 닫히지 않습니다. –

+0

제발, 제 편집을 참조하십시오. – sergio

+0

제대로 작동하지 않습니다. View Controller B는 세로 모드로 회전 할 때 해제되지 않습니다. –

0

코드를 willAnimateRotationToInterfaceOrientation:에서 didRotateFromInterfaceOrientation:으로 이동하고 toInterfaceOrientation 대신 self.interfaceOrientation을 사용하는 것이 좋습니다.

0

보기 컨트롤러 B는 가로 방향으로 나타납니다. ;가 지원하는 방향 반환 YES 대한 (UIInterfaceOrientation) interfaceOrientation {

// 반환 YES :

  • (BOOL) shouldAutorotateToInterfaceOrientation : 여기에보기 컨트롤러 B의 구현

}

- (무효) willAnimateRotationToInterfaceOrientation : (UIInterfaceOrientation) toInterfaceOrientation 시간 : (NSTimeInterval) 기간 {

if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
    NSLog(@"dismissing chart"); 
    [self dismissModalViewControllerAnimated:NO]; 
} 

}

0

당신이 함수 willRotateToInterfaceOrientation을 구현 했습니까? 또한 알림 센터를 사용하여 모달보기 컨트롤러에 모달 뷰 컨트롤러가 회전되었음을 알리고 간단히 [self dismissModalViewControllerAnimated : YES]

0

항상 didRotateFromInterfaceOrientation에 방향 논리를 씁니다. 다음은 .... 잘 작동 내 코드의 일부이다

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     [connectCoverLockUnlockSwitch setFrame:CGRectMake(250,6,51,31)]; 
     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

     if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight){ 

      [connectCoverLockUnlockSwitch setFrame:CGRectMake(400,6,51,31)]; 
      [self.tableView reloadData]; 
     } 
     else if (orientation == UIDeviceOrientationPortraitUpsideDown || orientation == UIDeviceOrientationPortrait){ 

     [connectCoverLockUnlockSwitch setFrame:CGRectMake(250,6,51,31)]; 

} }

else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)  { 
      UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];   

     if (orientation == UIDeviceOrientationUnknown || orientation == UIDeviceOrientationFaceUp) { 

//return; 

    } 
     if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) { 
       [connectCoverLockUnlockSwitch setFrame:CGRectMake(570,6,51,31)]; 

       [self.tableView reloadData]; 
     } 

    else if (orientation == UIDeviceOrientationPortraitUpsideDown || orientation == UIDeviceOrientationPortrait) 
     { 
      [connectCoverLockUnlockSwitch setFrame:CGRectMake(330,6,51,31)]; 
      [self.tableView reloadData]; 

      } 
      } 
관련 문제