How to make a blinking (or flashing) cursor on iphone?(如何在 iPhone 上制作闪烁(或闪烁)的光标?)
问题描述
我正在尝试在 UIKit 中创建一个自定义的闪烁光标",我已经尝试如下所示,有 2 个函数基本上会一直相互调用,直到光标被隐藏.但这会导致一个很好的无限递归......由于某种原因,这些函数会立即相互调用,而不是像预期的那样每半秒调用一次.
I'm trying to create a custom "blinking cursor" in UIKit, I've tried as shown below, having 2 functions that basically keep calling each other until the cursor is hidden. But this leads to a nice infinite recursion... for some reason the functions call each other right away, not each half-second as expected.
如果 'finished' 参数不是 YES,我尝试返回(通过取消注释 'if (!ok)' 行),但这根本不会导致动画...
I tried returning if the 'finished' parameter is not YES (by uncommenting the 'if (!ok)' line), but that leads to no animation at all...
有更好的主意吗?我错过了什么吗,有没有更简单的方法来制作闪烁光标"?
Any better idea? Did I miss something, is there a much-easier way to make a "blinking cursor"?
- (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];
}
推荐答案
在委托上:
- (void)blinkAnimation:(NSString *)animationId finished:(BOOL)finished target:(UIView *)target
{
if (shouldContinueBlinking) {
[UIView beginAnimations:animationId context:target];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(blinkAnimation:finished:target:)];
if ([target alpha] == 1.0f)
[target setAlpha:0.0f];
else
[target setAlpha:1.0f];
[UIView commitAnimations];
}
}
然后开始动画:
shouldContinueBlinking = YES;
[self blinkAnimation:@"blinkAnimation" finished:YES target:cursorView];
另外,确保你的类有一个 shouldContinueBlinking 实例变量
Also, ensure your class has a shouldContinueBlinking instance variable
这篇关于如何在 iPhone 上制作闪烁(或闪烁)的光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iPhone 上制作闪烁(或闪烁)的光标?
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
