2012-08-23 135 views
1

後,我試圖讓我的標籤顯示動畫:addSubview動畫作品只有第二次

- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer { 
    if (isShowingRectangleLabel == NO) { 
    [UIView transitionWithView:rectangleLabel duration:0.5 
         options:UIViewAnimationOptionTransitionCrossDissolve 
        animations:^ { [self.view addSubview:rectangleLabel]; } 
        completion:nil]; 
     NSLog(@"action"); 
     isShowingRectangleLabel = YES; 
    } else { 
     [UIView transitionWithView:rectangleLabel duration:0.5 
         options:UIViewAnimationOptionTransitionFlipFromBottom 
        animations:^ { [rectangleLabel removeFromSuperview]; } 
        completion:nil]; 
     isShowingRectangleLabel = NO; 
    } 

} 

但這僅動畫後第二次增加了子視圖的工作。我該如何解決它?

編輯澄清,addSubview工程,但沒有動畫。

+0

只是可以肯定:你驗證* isShowingRectangleLabel *是當你試圖在第一時間設置爲NO? –

+0

是的,在'viewDidLoad'中我將它設置爲'NO'。 – RomanHouse

回答

3

這樣做:

- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer { 
    if (isShowingRectangleLabel == NO) { 
    [UIView transitionWithView:self.view duration:0.5 
         options:UIViewAnimationOptionTransitionCrossDissolve 
        animations:^ { [self.view addSubview:rectangleLabel]; } 
        completion:nil]; 
     NSLog(@"action"); 
     isShowingRectangleLabel = YES; 
    } else { 
     [UIView transitionWithView:self.view duration:0.5 
         options:UIViewAnimationOptionTransitionFlipFromBottom 
        animations:^ { [rectangleLabel removeFromSuperview]; } 
        completion:nil]; 
     isShowingRectangleLabel = NO; 
    } 

} 
+0

我不注意:(謝謝,它的作品。 – RomanHouse