2013-08-26 4 views
1

메서드를 만들고 animateWithDuration에서 BOOL 유형을 반환하려고합니다. 하지만 내 개체가 완료 블록에서 감지되지 않는 것 같습니다. 누군가 나에게 설명 할 수있는 이유는 무엇일까요?animateWithDuration에서 BOOL을 반환하는 방법은 무엇입니까?

+ (BOOL)showAnimationFirstContent:(UIView *)view { 
    BOOL status = NO; 

    CGRect show = [SwFirstContent rectFirstContentShow]; 

    [UIView animateWithDuration:DURATION 
          delay:DELAY 
         options:UIViewAnimationOptionBeginFromCurrentState 
        animations:^{ view.frame = show; } 
        completion:^(BOOL finished) { 
         status = YES; 
        }]; 
    return status; 
} 

감사합니다.

답변

3

완료 될 때 부울 처리 완료 블록의 방법을 실행해야 . 의미, 귀하의 반환 진술은 블록이 실행 된 후 실행 보장되지 않습니다. 애니메이션이 끝난 시점을 알려면 다른 방법으로 메소드를 선언해야합니다.

+ (void)showAnimationFirstContent:(UIView *)view completion:(void (^)(void))callbackBlock{ 

    CGRect show = [SwFirstContent rectFirstContentShow]; 

    [UIView animateWithDuration:DURATION 
          delay:DELAY 
         options:UIViewAnimationOptionBeginFromCurrentState 
        animations:^{ view.frame = show; } 
        completion:^(BOOL finished) { 
         callbackBlock(); 
        }]; 
} 

그리고이 같은이 방법은 호출 할 수

[MyClass showAnimationFirstContent:aView completion:^{ 
//this block will be executed when the animation will be finished 
    [self doWhatEverYouWant]; 
}]; 

당신은 어떻게 block works에 대해 좀 더 읽을 수 있습니다.

희망이 도움이됩니다.

+1

나는 당신의 해결책과 그 일을 시도한다. 감사합니다 mamnun. –

2

블록이 비동기 적으로 실행되기 때문에 발생합니다. animateWithDuration 메서드를 실행 한 후에 showAnimationFirstContent 메서드는 애니메이션이 끝나기를 기다리지 않고 (그리고 부울 값을 YES으로 변경하지 않고) 계속 실행 (이 경우 반환)한다는 의미입니다.

하면 아마 애니메이션 클래스의 구성원이 부울 유지 애니메이션은 비동기 적으로 실행되어야하는 블록의 내부 상태 값을 설정하는

+0

감사합니다 giorashc, 이제 왜 내 개체가 블록에서 감지되지 않는지 이해합니다. –