2009-07-12 5 views
1

이것은 재미 있습니다 ... 도움말 화면이 있고 모달보기로 표시되는 응용 프로그램이 있습니다. 기본보기에는 장치가 흔들릴 때 발생하는 동작이 있습니다. 도움말 화면이 표시 될 때 동작이 발생하는 것을 원하지 않습니다 (사운드가 재생 됨).모달 뷰가 표시되었을 때 감지

- (IBAction)buttonPressed:(id) sender { 
    [self dismissModalViewControllerAnimated:YES]; 
} 

내가 시도 :

- (IBAction)helpButtonPressed:(id) sender { 
    helpViewController = [[HelpViewController alloc] init]; 
    [self presentModalViewController:helpViewController animated:YES]; 
} 

이 도움말 화면을 해제하려면 :

는 도움말 화면을 표시하려면 다음

여기 내 코드는 ... 몇 가지 시도 성공하지 못한 다음과 같은 :

if ([helpViewController.view isHidden ]) { 
    NSLog(@"Shake -- helpView is loaded"); 
} else { 
    NSLog(@"Shake -- helpView is not loaded"); 
} 


if ([helpViewController isViewLoaded]) { 
    NSLog(@"Shake -- helpView is loaded"); 
} else { 
    NSLog(@"Shake -- helpView is not loaded"); 
} 

if ([self isViewLoaded]) { 
    NSLog(@"Shake -- helpView is loaded"); 
} else { 
    NSLog(@"Shake -- helpView is not loaded"); 
} 

내가 도움을 볼 수 있는지 감지 할 수있는 기능이 있다면 장치가 흔들릴 때 소리를 내지 않고 돌아올 것입니다 ....

아이디어가 있으십니까?

답변

2

모달 컨트롤러를로드하는보기 컨트롤러가 흔들기 동작에 응답하는보기 컨트롤러이기도합니다. 이 경우 부모보기 컨트롤러의 modalViewController 속성을 사용하여 모달 컨트롤러가 활성 상태인지 확인할 수 있습니다.

if(self.modalViewController != nil) { 
    // Modal view controller is active; do nothing 
    NSLog(@"Shake -- helpView is loaded"); 
    return; 
} else { 
    // No modal view controller; take action 
    NSLog(@"Shake -- helpView is not loaded"); 
    [self performSomeAction]; 
}
+0

완벽하게 작동합니다. 감사! –