我想在UIKit中創建一個自定義的「閃爍遊標」,我嘗試瞭如下所示,有兩個函數基本上保持相互調用,直到光標被隱藏。但是這導致了一個很好的無限遞歸......出於某種原因,這些函數立即互相調用,而不是像預期的那樣每半秒鐘。如何在iphone上閃爍(或閃爍)光標?
我試圖返回,如果「完成」參數不是YES(通過取消註釋「如果(!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];
}
上下文參數是一個空指針,而不是一個CGContextRef(雖然傳遞CGContextRef是有效的,它肯定不會是有用的) – rpetrich 2009-09-26 00:11:24