我正在制作一个Pebble watchface,在适当的Linux终端调用下显示数据和时间,以获取这些时间。
我有一个很好的,主要是静态的复制工作,但我试图添加一个打字动画的脸。

为此,我使用AppTimer 200ms,并在每次调用时多键入一个字母。
然而,现在我遇到了一个问题,即使我可以让命令动画化,我也不能让大的时间和日期文本消失(当命令完成键入时,它们会重新出现)。
这里有一些相关的代码,其余的在GitHub https://github.com/vidia/Pebble-Shell/tree/type上
我认为发生的情况是,文本的设置覆盖了颜色的设置,并使文本再次出现。但我不能完全确定。如果有必要,您可以自行安装。
static char hourmin[] = "~$date +%I:%M";
static char timecmd[] = " ";
static char monthday[] = "~$date +%h\\ %d";
static char datecmd[] = " ";
...
static void handleMinuteTick(...)
{
text_layer_set_text_color(time_layer, GColorClear);//the time text
text_layer_set_text_color(date_layer, GColorClear);//the date text
text_layer_set_text_color(dprompt_layer, GColorClear);//the date prompt
text_layer_set_text_color(prompt_layer, GColorClear);//the final, empty prompt
...
//set text of time_layer to the current time
//register a timer
}
static void animateTimePrompt()
{
static unsigned int i = 2;
static int TYPE_TIME = 200;
app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 97, "i: %d", i);
strncpy(timecmd, hourmin, i++);
app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 60, "timecmd: \"%s\"", timecmd);
text_layer_set_text(text_layer, timecmd);
if( i > strlen(hourmin))
{
app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 97, "Typed word!!: %d", i);
i = 2;
text_layer_set_text_color(time_layer, GColorWhite);
text_layer_set_text_color(dprompt_layer, GColorWhite);
//app_timer_cancel(timer);
timer = app_timer_register(TYPE_TIME, animateDatePrompt, 0);
}
else
timer = app_timer_register(TYPE_TIME, animateTimePrompt, 0);
}
static void animateDatePrompt()
{
static int i = 2;
static int TYPE_TIME = 200;
app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 97, "i: %d", i);
strncpy(datecmd, monthday, i++);
app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 60, "datacmd: \"%s\"", datecmd);
text_layer_set_text(dprompt_layer, datecmd);
if((unsigned int) i > strlen(monthday))
{
app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 97, "Typed word!!: %d", i);
i = 2;
text_layer_set_text_color(date_layer, GColorWhite);
text_layer_set_text_color(prompt_layer, GColorWhite);
//timer = app_timer_register(TYPE_TIME, animateDatePrompt, 0);
//app_timer_cancel(timer);
}
else
timer = app_timer_register(TYPE_TIME, animateDatePrompt, 0);
}
...
void handleSecondTick(...)
{
//set text of prompt_layer for the blinking cursor.
}发布于 2014-04-01 14:23:50
当你只想改变提示符的颜色时,我认为你正在改变整个文本层的颜色。我认为只创建一个层来显示提示符,然后在用户键入时移动提示符,可能会更容易。
https://stackoverflow.com/questions/22736837
复制相似问题