我怎样才能让在iPhone开发这个动画效果吗? Quartz2d,核心动画?(How can I

2019-10-18 04:01发布

我想提出的是不断增长的动画和文字(数字)也与杆长的价值成长一间酒吧。 看起来像:

酒吧应水平增长,与数字的文字也应该增长。 而且用户可希望用自来水再次播放动画“重播”。

阅读苹果的编程指南和一些伟大的教程后,我有一个大致的了解。 随着Quartz2d,我可以借鉴的酒吧,也是垂直线,也是文字以及。 但Quartz2d不具有动画效果。 随着核心动画,我可以用时间和指定的属性值改变杆的形状。 我说得对吗?

所以,我想我要的是结合Quartz2d和核心动画,先绘制Quartz2d酒吧,然后用CA的动画呢? 它是这样做的正确方法? 或者,如果任何其他轻量的解决方案可用,我将不胜感激。

PS:我是很新的iPhone图纸,因为据我所知,做动画的最轻的方式是通过UIView的动画,而较轻的一个是CALayer的动画。 而整个绘图工作是Quartz2d,我是不是正确的? 这是一种混淆即使我读了这篇文章 。 但要实用,我不(或不能)太概念对整个图形系统。 不过,我一定会继续挖掘后,写一些这方面的实际代码。

所以,现在,我只需要知道这是实现这个动画效果的最佳途径。

多谢你们 :)

Answer 1:

我会使用的东西像什么我已经写在下面。 它会增加你的框架用1.5秒的时间(当然,您可以更改时间)。 我不知道你用什么样的对象为你的形状。 你可以使用像一个UIView和设置backgroundColor到任何你想要的。

// calculate your new frame - not sure what your parameters are as you've not explained it in your question.
CGRect newFrame = CGRectMake(10, 10, 300, 40);  // arbitrary values to demonstrate process... 

[UIView animateWithDuration:1.5 animations:^{
    // grow your rect (assuming yourShape is a UIView)
    yourShape.frame = newFrame;
    yourLabel.center = CGPointMake(newFrame.size.width - yourLabel.frame.size.width, yourLabel.center.y)
} completion:^(BOOL finished) {
    // do anything here that needs to occur after..

}];

不知道究竟你通过不断增长的文本“(增加,或增加字体大小)的意思,所以我给出的例子,那就能让你在你的水平栏的末尾(右)文本)。 这应该给一个很好的起点用于试验UIView动画。


递增标签更新

你需要使用NSTimer来增加您的标签。 试试这个代码了。

在您的.h

int maxNum;
NSTimer *numTimer;

在您的m

使用此功能来启动计数。 你可能会想只是你之前把这个UIView动画。

maxNum = 100;  // make this whatever number you need..
// you can change the TimeInterval to whatever you want..
numTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(growNumbers:) userInfo:nil repeats:YES];

这是定时器每次触发(每0.03秒)时间调用选择器:

- (void)growNumbers:(id)sender {
    int i = self.numberLabel.text.intValue;
    if (i >= maxNum) {
        [numTimer invalidate];
        maxNum = 0;
    } else {
        i++;
        self.numberLabel.text = [NSString stringWithFormat:@"%i",i];
    }
}


文章来源: How can I make this animation effect in iPhone development? Quartz2d, Core Animation?