我想要做的是在计时器滴答时动画标签。 我有一个基于窗口的应用程序。核心动画和NSTimer
- 我在while循环中尝试了核心动画,但程序只是冻结。
- 我尝试了由定时器(NSTimer)触发的核心动画,但没有任何反应。
问题:我调试过的程序,一切都很好,所有的语句都在执行,但没有任何反应。我认为不允许在循环中或定时器触发的核心动画。有没有其他方法?
我有的是:
drawingTimer = [NSTimer scheduledTimeWithTimeInterval:60.0 target:self
selector:@selector(slideWords) userInfo:nil repeats:NO];
-void (slideWords){
randomNumber = 1 + arc4Random()%2;
if(randomNumber = 1){
Redlabel.alpha = 1.0;
RedLabel.frame = CGRectMake(0, -50, 320, 100);
[UIWindow animateWithDuration:5.0 animations:^{
Redlabel.alpha = 1.0;
Redlabel.frame = CGRectMake(0,300,320,100);
}completion:^(BOOL finished){
[UIWindow animateWithDuration:0.5 delay:0.5 options:0 animations:^{
Redlabel.alpha = 0.0;
}completion:^(BOOL finished){
}];
}];
}
if(randomNumber = 2){
GreenLabel.alpha = 1.0;
GreenLabel.frame = CGRectMake(0, -50, 320, 100);
[UIWindow animateWithDuration:5.0 animations:^{
GreenLabel.alpha = 1.0;
GreenLabel.frame = CGRectMake(0,300,320,100);
}completion:^(BOOL finished){
[UIWindow animateWithDuration:0.5 delay:0.5 options:0 animations:^{
GreenLabel.alpha = 0.0;
}completion:^(BOOL finished){
}];
}];
}
}
没有读完整个事情,但你的条件只是做作业。两者都将被评估为true,并改变randomNumber。另外,alpha级别被赋值为1,然后被赋值为1(no-op)。 – danh
当我只写在RedLabel.alpha .....休息的行;程序工作正常。问题应该由NSTimer或循环触发,所以我正在寻找替代品。 –
此外,您将两个标签的框架设置为相同的矩形,然后对同一矩形设置动画。一个将永远隐藏。我认为你应该重新开始并从根本上简化:没有循环或计时器,没有随机的。只需让一个标签消失并移动你想要的方式(可能会添加一个临时按钮来触发它)。然后做第二个标签。然后硬编码你想要的两个随机情况,然后添加随机...等等。你会到达那里! – danh