Blink hidden and using blocks

ⅰ亾dé卋堺 提交于 2020-01-14 05:20:07

问题


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) ?


回答1:


[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.




回答2:


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


来源:https://stackoverflow.com/questions/7820232/blink-hidden-and-using-blocks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!