2014-04-09 5 views
0

저는이 문제를 꽤 오랫동안 다루고 있으며 실제로 도움이 필요합니다. 시작시 보여주는 자습서보기가 있습니다. 나는 초상화와 풍경을위한 이미지를 가지고 있는데, 필요한 것은 장치가 회전하고 오른쪽 이미지를 선택할 때뿐입니다.UIInterfaceOrientation이 계속 반복해서 초기화되고 있습니다.

나는 간단한 것을 놓친다는 것을 알고있다. 그러나 여기에 내 코드가 있으며 도움을 주시면 감사하겠습니다.

- (void)orientationChanged:(NSNotification *)notification{ 
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]]; 
} 

- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation { 
if (IS_IPAD()) { 


if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown){ 

    self.searchPage = [LTutorialPage page]; 
    self.searchPage.title = MY_LOCALIZED_STRING(@"search_tutorial_label_1", nil); 
    self.searchPage.bgImage = [UIImage imageNamed:@"didactitiel-iPad-port01"]; 


    self.searchTutr = [[LTutorialView alloc] initWithFrame:rootView.bounds andPages:@[self.searchPage]]; 

    self.searchTutr.pageControl.hidden = YES; 

    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGFloat screenWidth = screenRect.size.width; 
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 

    [btn setFrame:CGRectMake((screenWidth-10), 30, 50, 50)]; 
    [btn setImage:[UIImage imageNamed:@"Close.png"] forState:UIControlStateNormal]; 

    self.searchTutr.skipButton = btn; 
    [self.searchTutr setDelegate:self]; 
    [self.searchTutr showInView:rootView animateDuration:0.3]; 
    } 

    else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight){ 
    self.searchPage = [LTutorialPage page]; 
    self.searchPage.title = MY_LOCALIZED_STRING(@"search_tutorial_label_1", nil); 
    self.searchPage.bgImage = [UIImage imageNamed:@"didactitiel_iPad_land01"]; 


    self.searchTutr = [[LTutorialView alloc] initWithFrame:rootView.bounds andPages:@[self.searchPage]]; 

    self.searchTutr.pageControl.hidden = YES; 

    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGFloat screenWidth = screenRect.size.width; 
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 

    [btn setFrame:CGRectMake((screenWidth-10), 30, 50, 50)]; 
    [btn setImage:[UIImage imageNamed:@"Close.png"] forState:UIControlStateNormal]; 

    self.searchTutr.skipButton = btn; 
    [self.searchTutr setDelegate:self]; 
    [self.searchTutr showInView:rootView animateDuration:0.3]; 

    } 
    } 
} 

현재 상황은 기기가 회전 할 때마다 자습서보기를 계속 추가한다는 것입니다. 따라서 장치를 5 번 회전하면 5 개의보기가 추가됩니다.

미리 감사드립니다.

+0

왜 당신이 당황하십니까? 회전 처리 코드는 호출 될 때마다 새로운'LTutorialView'를 생성하고 추가합니다. 왜 이런 일이 일어나고 있는지, 아니면 코드를 변경하여 처음으로 추가 한 뷰를 재사용 할 수 있는지 궁금한가요? – rmaddy

+0

@rmaddy 내 질문에 코드를 변경하는 방법 그래서 내가 추가 한 첫 번째보기를 재사용? – Hassan

답변

0

알림을 등록하는 대신 다음을 시도해 보셨습니까?

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 

또는 심지어;

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; 
+0

작동하지 않지만 여전히 동일한 동작을 수행하며 매 회전마다 뷰를 계속 추가합니다. – Hassan