2013-01-08 2 views
0

모달 창과 같이 보이거나 숨기는 UISegmentedControl이 있습니다. 처음에는 선택한 세그먼트가 없습니다. IB에서 값 변경 이벤트는 - (IBAction) cardClassificationChanged : (UISegmentedControl *) 보낸 사람에게 연결됩니다. 내가 마지막 줄 (-hideWithAnimation에 대한 호출을) 주석 경우애니메이션 전에 UISegmentedControl 선택이 업데이트되지 않습니다.

- (IBAction)cardClassificationChanged:(UISegmentedControl *)sender 
{ 
    NSLog(@"%d", sender.selectedSegmentIndex); 
    // block for updating the categorization of current card asynchronously 
    [self.cardActionSheet hideWithAnimation]; 
} 

이 예상대로 선택이 변경, 모든 작품 : 여기에 그 방법이다. 그러나 해당 애니메이션 메서드를 호출하면 UISegmentedControl 선택 항목이 애니메이션 전에 시각적으로 변경되지 않습니다.

- (void)hideWithAnimation 
{ 
    CATransition *animation = [CATransition animation]; 
    animation.type = kCATransitionFade; 
    animation.duration = globalAnimationLength; 
    [self.layer addAnimation:animation forKey:nil]; 

    self.hidden = YES; 
} 

이 뷰 (a에서 터치 동작) 다음에 나타나는 시간은 UISegmentedControl 비록 선택된 정확한 세그먼트를 가질 것이다 : 여기 hideWithAnimation 방법이다.

UISegmentedControl에 setNeedsDisplay를 호출 할 필요는 없지만 cardClassificationChanged 메서드 나 hideWithAnimation 메서드로 실험 할 때도 새로 고쳐지지 않습니다.

분명히 UI 업데이트와 관련된 뭔가가 누락되었습니다. 애니메이션보다 먼저 UISegmentedControl 선택 항목을 업데이트하려면 무엇을 호출해야합니까?

+1

에서 호출되지 않습니다 -hideWithAnimation' 방법을'시도'-cardClassificationChanged :','-hideCardActionSheet이'대신이라고합니다. 복사 된 코드를 확인하고 수정 해 주시겠습니까? –

+0

네 말이 맞아. 혼란스러워서 미안해. -hideCardActionSheet에는 다른 논리/처리가 있고 -hideWithAnimation이 호출됩니다. 나는 그 기계로 돌아갈 수있을 때 갱신 할 것이다. 현재로서는 cardClassificationChanged 내부의 애니메이션이나 로직에 문제가 없지만 UISegmentedControl이 선택을 반영하여 시각적으로 업데이트되지 않는다는 점이 문제점입니다. – aaronfalls

+0

@ A-Live 편집 됨, 지적 해 주셔서 감사합니다. – aaronfalls

답변

0

컨트롤을 페이드 아웃하기 위해 UIKit 애니메이션을 사용해야합니다. 다음 코드

- (void)hideWithAnimation 
{ 
    [UIView animateWithDuration:0.2 
       animations:^{ 
        self.alpha = 0.; 
       } completion:^(BOOL finished) { 
        self.alpha = 1.; 
        self.hidden = YES; 
       }]; 
} 
+0

이 블록 기반 애니메이션을 사용하여 문제가 해결되었고 더 현대적인 코드입니다. :) 대단히 감사합니다. UISegmentedControl이 CATransition 접근법으로 업데이트되지 않는 이유에 대해 제공 할 수있는 참조 또는 의견은 (내 자신의 이해를 위해) 높이 평가 될 것입니다. – aaronfalls

+1

@afalls'[self performSelector : @selector (hideWithAnimation :) withObject : sender afterDelay : 0];으로 애니메이션을 호출하면 스레드와 관련되어야합니다. (메인 스레드에서 키는 지연, 심지어 그것이 0 인 경우) 그것은 잘 작동합니다 'CATransition' –

관련 문제