闪烁隐藏和使用块

时间:2011-10-19 10:56:32

标签: iphone ios core-animation objective-c-blocks

我有方法:

- (void)blinkView:(UIView *)view
{
    view.layer.opacity = 0.0f;
    view.hidden = NO;

    [UIView beginAnimations:@"Blinking" context:nil];
    [UIView setAnimationRepeatCount:1.0];
    [UIView setAnimationDuration:0.6f];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    view.layer.opacity = 1.0f;
    [UIView commitAnimations];
}

如何使用块编写此代码,以及如何实现具有反向效果的方法(使用闪烁隐藏uiview)?

2 个答案:

答案 0 :(得分:3)

[UIView transitionWithView: view
       duration:0.6f
       options:UIViewAnimationOptionCurveEaseInOut
       animations:^{ view.layer.opacity = 1.0f; }
       completion:NULL];

[UIView transitionWithView: view
       duration:0.6f
       options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
       animations:^{ view.layer.opacity = 1.0f; }
       completion:NULL];

您可以通过递归调用动画块来设置重复计数(请参阅here)。

希望它会对你有所帮助。

答案 1 :(得分:0)

您可以使用 UIView setAnimationDelegate: setAnimationDidStopSelector:

[UIView beginAnimations:@"Blinking" context:nil];
[UIView setAnimationRepeatCount:1.0];
[UIView setAnimationDuration:0.6f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
view.layer.opacity = 1.0f;
[UIView commitAnimations];


- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    // add your final code here : you can give new animation effect here.
}

或尝试 animateWithDuration (仅在iOS 4或更高版本中可用)

[UIView animateWithDuration:0.6f
                 animations:^{
                             view.layer.opacity = 1.0f;
                             }
                 completion:^(BOOL  completed){
// add your final code here : you can give new animation effect here.
                                              }
                                           ];