2012-08-23 41 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