2012-11-27 61 views
0

我写了一个自定义的UITableViewCell - 图像视图,按钮和三个标签,现在我正试图给它添加一些动画。所以一旦我点击按钮,它就会消失,微调代替按钮。两秒钟后,细胞被红色覆盖,随着细胞的子视图淡入,指示器被移除,红色覆盖层开始消退。还有我以前删除按钮淡入回UITableViewCell动画错误

(我无法短语它一个更好的方法:P)。

的方法是:

-(void)rentButtonPressed:(id)sender 
{ 

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 
    [indicator startAnimating]; 
    indicator.center = self.rentButton.center; 

    [UIView animateWithDuration:0.2 
        animations:^{self.rentButton.alpha = 0.0;} 
        completion:^(BOOL finished){ 
         [self.rentButton removeFromSuperview]; 
         [self addSubview:indicator]; 
        } 
    ]; 

    UIView *overlay = [[UIView alloc] initWithFrame:self.backgroundImage.frame]; 
    overlay.alpha = 0.0; 
    overlay.backgroundColor = [UIColor redColor]; 
    [self.contentView addSubview:overlay]; 

    [UIView animateWithDuration:0.4 
          delay:2.0 
         options:UIViewAnimationCurveEaseInOut 
        animations:^{ 
          [indicator removeFromSuperview]; 
          overlay.alpha = 0.4; 
         } 
        completion:^(BOOL finished){ 
         [UIView animateWithDuration:0.4 
             animations:^{ overlay.alpha = 0.0; } 
             completion:^(BOOL finished) 
             { 
              [overlay removeFromSuperview]; 
             } 
         ]; 

         [self.contentView addSubview:self.rentButton]; 
         [UIView animateWithDuration:0.4 animations:^{ self.rentButton.alpha = 1.0;}]; 
         [self.delegate didTryToRentMovieAtCell:self]; 
        } 
    ]; 

} 

因此,代码不会淡出按钮,将其替换为微调框并淡入红色覆盖层。问题是,红色覆盖层不会消失,而是与按钮一样消失,而不是消失,它刚刚出现。

回答

2

在动画过程中,您将通过添加和删除子视图来更改视图层次结构。 UIView类方法animateWithDuration:动画:完成仅用于动画视图中的属性更改,而不用于更改视图层次结构。

尝试使用UIView类方法transitionWithView:duration:options:animations:completion:改为使用单元格的内容视图作为“容器”。

本文档是有帮助的动画视图属性的更改和动画视图过渡之间的区分,特别是部分“更改视图的子视图”: http://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html

+0

不,这不会帮助下,这个问题”不是个t时间,它的事实是它们(视图)不会在完成处理器动画中淡入淡出。 – foFox

+0

对不起@foFox误解了你的问题。检查我更新的答案,看看是否有帮助。 – jal72088