【问题标题】:Why isn't this shape animating?为什么这个形状没有动画?
【发布时间】:2012-12-29 06:40:30
【问题描述】:

我很困惑为什么这个形状不会动画到另一条路径。我已经尝试过演示 CABasicAnimations,它已经成功了。如果有人有任何想法,那就太棒了!

#import "AKTabBar.h"

@implementation AKTabBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        //customize tab bar
    }
    return self;
}

-(void)awakeFromNib {
    CAShapeLayer* tabBarShape = [CAShapeLayer layer];


    UIBezierPath* discoverPath = [UIBezierPath bezierPath];
    [discoverPath moveToPoint: CGPointMake(0, 98)];
    [discoverPath addLineToPoint: CGPointMake(0, 98)];
    [discoverPath addLineToPoint: CGPointMake(0, -0)];
    [discoverPath addLineToPoint: CGPointMake(27.91, -0)];
    [discoverPath addLineToPoint: CGPointMake(34, 7)];
    [discoverPath addLineToPoint: CGPointMake(39.78, -0)];
    [discoverPath addLineToPoint: CGPointMake(320, -0)];
    [discoverPath addLineToPoint: CGPointMake(320, 98)];
    [discoverPath closePath];


    UIBezierPath* sharePath = [UIBezierPath bezierPath];
    [sharePath moveToPoint: CGPointMake(0, 98)];
    [sharePath addLineToPoint: CGPointMake(0, 98)];
    [sharePath addLineToPoint: CGPointMake(0, -0)];
    [sharePath addLineToPoint: CGPointMake(40, -0)];
    [sharePath addLineToPoint: CGPointMake(47, 7)];
    [sharePath addLineToPoint: CGPointMake(39.78, -0)];
    [sharePath addLineToPoint: CGPointMake(320, -0)];
    [sharePath addLineToPoint: CGPointMake(200, 98)];
    [sharePath closePath];

    tabBarShape.path=discoverPath.CGPath;
    tabBarShape.fillColor = [UIColor redColor].CGColor;

//    UIImageView* menu = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabBarBackground"]];
    [self.layer addSublayer:tabBarShape];
//    menu.layer.mask=tabBarShape;
//  [ self addSubview:menu];


    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"discoverPath"];
    animation.duration = 4.0;
    animation.toValue = (__bridge id)(sharePath.CGPath);
    [tabBarShape addAnimation:animation forKey:@"discoverPath"];


}


@end

【问题讨论】:

    标签: ios core-animation calayer


    【解决方案1】:

    您的CABasicAnimation 正在尝试为CAShapeLayer 上的属性discoverPath 设置动画。但是,CAShapeLayer 没有这样的属性。

    如果你改为这样做会发生什么?

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 2014-03-16
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 2023-01-10
    相关资源
    最近更新 更多