闪烁隐藏并使用块

我有方法:

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

 [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]; 

您可以通过recursion调用animation块来设置重复次数(请参见此处 )。

希望它会帮助你。

你可以使用UIViewsetAnimationDelegate: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. } ];