Blink hidden and using blocks

2019-06-13 03:25发布

I have the method:

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

How can i write this code with blocks, and how i must implement method with reverse effect (hide uiview with blink) ?

2条回答
何必那么认真
2楼-- · 2019-06-13 03:57
[UIView transitionWithView: view
       duration:0.6f
       options:UIViewAnimationOptionCurveEaseInOut
       animations:^{ view.layer.opacity = 1.0f; }
       completion:NULL];

or

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

You can set the repeat count by recursively calling the animation block (see here).

Hope it will help you.

查看更多
Luminary・发光体
3楼-- · 2019-06-13 04:05

You can use UIView's setAnimationDelegate: and 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.
}

Or try animateWithDuration (available only in iOS 4 or later)

[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.
                                              }
                                           ];
查看更多
登录 后发表回答