1

我试图让我的标签出现动画:

- (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作品但没有动画。

4

1 回答 1

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;
    }

}
于 2012-08-23T08:09:49.610 回答