2012-02-29 7 views
0

모달 뷰 디스플레이에 문제가 있습니다. 내 첫 번째보기가 아주 잘 돌아 간다. 모달 뷰의 컨트롤러는 "ShouldAutorotationToInterfaceRotation"메서드를 구현하지만 장치 또는 시뮬레이터를 회전하면 모달 뷰가 회전하지 않습니다.모달 뷰가 회전하지 않습니다.

첫 번째보기가 모달보기 대신 회전 이벤트를 감지했지만 아니요, 이벤트를받지 못하는지 확인하기 위해 몇 가지 의견을 추가했습니다.

실마리가 있습니까?

답변

1

모달 뷰의 회전 이벤트를 수신하려면 NSNotificationCenter에 가입해야합니다. 그런 다음 모달 뷰를 아래쪽 뷰와 관련하여 올바르게 배치하려면 한 가지 해결 방법은 뷰를 변형하는 것입니다.

있는 viewDidLoad에 넣고 및 각도로 원래 방향을 저장 (NSNotification *)는 코드 통지 올바르게 상대 회전 :

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) 
              name:UIDeviceOrientationDidChangeNotification object:nil]; 

int initialOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 
if (initialOrientation == UIDeviceOrientationPortrait) 
    initialAngle = 0.0; 
else if (initialOrientation == UIDeviceOrientationLandscapeRight) 
    initialAngle = 90.0; 
else if (initialOrientation == UIDeviceOrientationPortraitUpsideDown) 
    initialAngle = 180.0; 
else if (initialOrientation == UIDeviceOrientationLandscapeLeft) 
    initialAngle = 270.0; 

currentAngle = initialAngle; 

그 다음 함수 가 orientationChanged 정의 다음은 일 실시 예이다 초기 방향으로 :

int newOrientation = [[notification object] orientation]; 
if (newOrientation == UIDeviceOrientationPortrait) 
    desiredAngle = 0.0; 
else if (newOrientation == UIDeviceOrientationLandscapeRight) 
    desiredAngle = 90.0; 
else if (newOrientation == UIDeviceOrientationPortraitUpsideDown) 
    desiredAngle = 180.0; 
else if (newOrientation == UIDeviceOrientationLandscapeLeft) 
    desiredAngle = 270.0; 

if(desiredAngle != currentAngle) 
{ 
    CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI * (-desiredAngle+initialAngle)/180.0);  
    CGAffineTransform translate = CGAffineTransformMakeTranslation(0, 0); 
    [[self releaseView] setTransform:CGAffineTransformConcat(translate, rotate)]; 
} 
currentAngle = desiredAngle; 
관련 문제