如何在iOS中的圆形路径上对标签进行动画处理? [英] how to animation a label on circular path in iOS?

查看:81
本文介绍了如何在iOS中的圆形路径上对标签进行动画处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,我只能对uiLabel进行动画处理.

I am stuck at animating the uiLabel in my view.

实际上,我只想在圆形路径上设置标签/文本的动画.我在互联网上进行了很多搜索,但找不到能解决类似我的问题的任何好的教程或示例.我已经做了CAShapeLayer(圆圈)从0增加到最大值....

Actually I just want to animate my label/Text on a circular path. I have searched a lot over internet but couldn't find any good tutorial or example that is doing something like my problem. I have done CAShapeLayer (circle) increasing from 0 to its maximum value....

同样,我希望我的标签/文本从圆形路径的起始点开始移动,并在完成一个圆之后返回其起始点.

Similarly I want that my label/text start moving from initial point in circular path and come back to its initial point after completing one circle.

希望我已经非常精确地解释了我的问题...仍然存在任何遗漏或无法理解的问题.请问我.

Hope I have explained my problem quite precisely ... still if there is anything missing or non-understandable. please ask me.

感谢您的期待.

推荐答案

iOmi我用谷歌搜索了一下,发现了与您的

Hi iOmi i just google it and i found Best Question similar like your This

下面是一个答案,希望它对您有帮助

Bellow it's a jin's answer Hope its helps you

        CAShapeLayer* circle = [[CAShapeLayer alloc] init];
        CGMutablePathRef path = CGPathCreateMutable();
        CGRect textRect = CGRectMake(self.view.bounds.size.width/4, (self.view.bounds.size.height-self.view.bounds.size.width/2)/2, self.view.bounds.size.width/2, self.bounds.size.width/2);
        float midX = CGRectGetMidX(textRect);
        float midY = CGRectGetMidY(textRect);
        CGAffineTransform t = CGAffineTransformConcat(
                                CGAffineTransformConcat(
                                    CGAffineTransformMakeTranslation(-midX, -midY), 
                                    CGAffineTransformMakeRotation(-1.57079633/0.99)), 
                                CGAffineTransformMakeTranslation(midX, midY));
        CGPathAddEllipseInRect(path, &t, textRect);
        circle.path = path;
        circle.frame = self.bounds;
        circle.fillColor = [UIColor clearColor].CGColor;
        circle.strokeColor = [UIColor blackColor].CGColor;
        circle.lineWidth = 60.0f;
        [self.layer addSublayer:circle];

        CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        animation.duration = 15.0f;
        animation.fromValue = [NSNumber numberWithFloat:0.0f];
        animation.toValue = [NSNumber numberWithFloat:1.0f];
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
        [circle addAnimation:animation forKey:@"strokeEnd"];

        [circle release];

        UILabel* label = [[UILabel alloc] init];
        label.text = @"Test Text";
        label.font = [UIFont systemFontOfSize:20.0f];
        label.center = CGPathGetCurrentPoint(path);
        label.transform = CGAffineTransformMakeRotation(1.57079633);
        [label sizeToFit];
        [self.layer addSublayer:label.layer];

        CAKeyframeAnimation* textAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        textAnimation.duration = 15.0f;
        textAnimation.path = path;
        textAnimation.rotationMode = kCAAnimationRotateAuto;
        textAnimation.calculationMode = kCAAnimationCubicPaced;
        textAnimation.removedOnCompletion = NO;
        [label.layer addAnimation:textAnimation forKey:@"position"];

我只是为其创建一个演示,屏幕截图是:-

i just create a demo of it screen shot is:-

这里是演示链接

http://www.sendspace.com/file/dq5i1e

这篇关于如何在iOS中的圆形路径上对标签进行动画处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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