我怎么可以在iPhone开发这个动画效果吗? Quartz2d,核心动画? [英] How can I make this animation effect in iPhone development? Quartz2d, Core Animation?

查看:158
本文介绍了我怎么可以在iPhone开发这个动画效果吗? Quartz2d,核心动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What I would like to make is a bar with growing animation and the text(number) also growing with the value of bar length. It looks like:

酒吧应水平增长,与数字的文本应该过长。而用户可能希望通过龙头重播再次播放动画。

The bar should be growing horizontally and the text with number should grow too. And the user may be want to play the animation again by tap "Replay".

阅读苹果的编程指南和一些伟大的教程后,我有一个大致的了解。随着Quartz2d,我可以借鉴的吧,也是垂直线,也是文本。但Quartz2d不具有动画效果。随着核心动画,我可以通过时间和指定的属性值来更改栏的形状。我说的对这个?

After read apple programming guide and some great tutorials, I have a general idea. With Quartz2d, I could draw the bar and also the vertical line, and also the text as well. But Quartz2d does not have animation effect. With Core Animation, I could change the shape of the bar by time and specified properties value. Am I right on this?

所以,我想我要的是结合Quartz2d和核心动画,先绘制Quartz2d酒吧,然后使用CA动画呢?是不是这样做的正确方法?或者,如果任何其他轻质解决方案可用,我必多多加AP preciate。

So I guess what I want is combine Quartz2d and Core Animation, draw the bar with Quartz2d first and then use CA to animate it? Is it the correct way to do this? Or if any other light-weight solution available, I will greatly appreciate.

PS:我是很新的iPhone的绘图,因为据我所知,做动画的最轻的方式是通过UIView的动画,和打火机之一是CALayer的动画。而整个绘图工作是Quartz2d,我是不是正确的?这是一种混淆即使我读<一个href=\"http://stackoverflow.com/questions/1877987/whats-the-difference-between-quartz-core-core-graphics-and-quartz-2d\">this帖子。但要实用,我不(或不能)太概念对整个图形系统。不过,我一定会不断挖掘之后写一些实际的code这一点。

PS: I'm very new to iPhone drawing, as far as I know, the lightest way to do animation is by UIView animation, and the lighter one is by CALayer animation. And the whole drawing work is by Quartz2d, am I correct? It's kind of confusing even after I read this post. But to be practical, I do not (or not able to) get too conceptual about the whole graphic system. But I will definitely keep digging after write some actual code about this.

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

So, right now, I just need to know if this is the best way to realize this animation effect.

谢谢你们:)

推荐答案

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

I would use something like what I've written below. It'll grow your frame over the course of 1.5 seconds (of course, you can change the duration). I'm not sure what kind of object you're using for your shape. You can just use something like a UIView and set the backgroundColor to whatever you want.

// 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 来增加您的标签。试试这个code了。

You'll need to use an NSTimer to increment your label. Try this code out.

在.H

int maxNum;
NSTimer *numTimer;

在您的m

使用此开始你的计数。你可能会想只是你的的UIView 动画之前把这个。

Use this to start your counting. You'll probably want to put this just before your UIView animations.

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秒)调用选择:

This is the selector the timer calls each time it fires (every 0.03 seconds):

- (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];
    }
}

这篇关于我怎么可以在iPhone开发这个动画效果吗? Quartz2d,核心动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆