我是iOS开发新手。当我按下秒表开始按钮时,我想显示计时器,如计数器令牌效果。我附上了图像供您参考。我已经完成了显示秒和分钟,但我不知道,如何动画自动滚动效果?我怎样才能做到这一点?
When the counter is moving it shouldn't jump from one number to another number, instead it should move from one number to next number smoothly, just like the petrol pump meter. Thanks
我以前做过类似的事情 - 这段代码不一定干净,但它可以完成工作。
你想创建两个UILabel
.h 文件中的 s:
IBOutlet UILabel *figureLabel1;
IBOutlet UILabel *figureLabel2;
然后你想创建一个BOOL
这样我们就可以知道哪个UILabel
对用户可见。
BOOL firstLabel;
因此,让我们想象一下初始标签(显示数字 1)是figureLabel1
和未来UILabel
要显示的(显示数字 2)是figureLabel2
。然而,当计数器加一时,则figureLabel2
向上移动并采取figureLabel1
的地方。然后,虽然figureLabel1
被隐藏,它取代了figureLabel2
when figureLabel1
是可见的。
看这里:
// Check what label is showing
if (firstLabel == YES) {
// Following code the hide and move the figureLabel1
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate: self]; //or some other object that has necessary method
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
// Slowing fade out the figureLabel1
[figureLabel1 setAlpha:0];
// Move the figureLabel1 up and out of the way
[figureLabel1 setFrame:CGRectMake(20, 108, 287, 55)];
[UIView commitAnimations];
// Following code the show and move the figureLabel2
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
// Slowing fade in the figureLabel2
[figureLabel2 setAlpha:1];
// Move the figureLabel2 up and into position
[figureLabel2 setFrame:CGRectMake(20, 141, 287, 55)];
[UIView commitAnimations];
// Update BOOL for next label
firstLabel = NO;
} else {
// Exactly the same but opposite
}
正如我所说,这并不漂亮,但它显示了基本概念。一切顺利!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)