-2
[UIView animateWithDuration:1.0 animations:^(void) {
    im.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
    [UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationCurveEaseOut animations:^(void) {
        im.alpha = 0.0;
    } completion:^(BOOL finished) {
        [im removeFromSuperview];
    }];    
}];

我知道,该代码用于制作动画UIImageView;我想知道调用机制,因为我还没有第一次看到这种函数调用。

主要是什么以及^(void)为什么传递 im.transform = CGAffineTransformIdentity;给它?

我已经浏览了 Apple 文档,以找到与此函数调用相关的任何内容,我也得到了它,但我没有从那里得到任何想法;或者我可能去过错误的部分。

这里有人可以指导我吗?

4

1 回答 1

4

这称为块,在 iOS 4 和 Mac OS X 10.6 中引入。

以下是一些链接,您可以在其中了解有关它们的更多信息:

上面的示例应如下所示:

// Start an animation over the next 1 second 
[UIView animateWithDuration:1.0 animations:^(void) {

    // For this animation, animate from the current value of im.transform back to the identity transform
    im.transform = CGAffineTransformIdentity;

} completion:^(BOOL finished) {  // At the completion of the first animation...

    // Wait 1 second, then start another 1-second long animation
    [UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationCurveEaseOut animations:^(void) {

        im.alpha = 0.0;  // Fade out im during this animation

    } completion:^(BOOL finished) {  // When you complete this second animation
        [im removeFromSuperview];  // Remove im from its superview
    }];    
}];

因此,您将有一秒钟的时间让 im 动画移除其变换,一秒钟的延迟,然后是一秒钟的 im 淡出。

于 2012-01-25T06:52:51.637 回答