我正在尝试在UIKit中创建一个自定义的"闪烁光标",我尝试过如下所示,有2个功能基本上一直保持相互调用,直到光标被隐藏.但这导致了一个很好的无限递归...由于某种原因,这些函数会立即相互调用,而不是像预期的那样每半秒.
我尝试返回如果'finished'参数不是YES(通过取消注释'if(!ok)'行),但这导致根本没有动画......
有什么好主意吗?我错过了什么,是否有一种更简单的方法来制作一个"闪烁的光标"?
- (void)onBlinkIn:(NSString *)animationID finished:(BOOL)ok context:(void *)ctx {
if (cursorView.hidden) return;
//if (!ok) return;
[UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(onBlinkOut:finished:context:)];
cursorView.textColor = [UIColor grayColor];
[UIView commitAnimations];
}
- (void)onBlinkOut:(NSString *)animationID finished:(BOOL)ok context:(void *)ctx {
if (cursorView.hidden) return;
[UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(onBlinkIn:finished:context:)];
cursorView.textColor = [UIColor clearColor];
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)