CALayer缩放动画的图层大小从左下角到右上角

时间:2012-03-23 10:12:41

标签: ios ios5 ios4

图层上的动画使其缩放并显示为从左下方增长的另一个问题,有点类似于图:

---------------    
|             |
|----------   |
|         |   |
|         |   |
|-----    |   |
|    |    |   |
---------------

我尝试了一些动画,但却无法按照我想要的方式实现。 请建议。目前使用以下代码进行扩展:

layer.anchorPoint = CGPointMake(1, 1);
CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
[scale setFromValue:[NSNumber numberWithFloat:0.0f]];
[scale setToValue:[NSNumber numberWithFloat:1.0f]];
[scale setDuration:1.0f];
[scale setRemovedOnCompletion:NO];
[scale setFillMode:kCAFillModeForwards];

3 个答案:

答案 0 :(得分:6)

您应该设置一个不同的anchorPoint来实现这种效果。

    layer.anchorPoint = CGPointMake(0.0f, 1.0f);

答案 1 :(得分:1)

所有这一切对我都不起作用。 修复框架和点的方法

- (CGRect) fixRect:(CGRect)rect inRect:(CGRect)container
{
    CGRect frame = rect;
    frame.origin.y = container.size.height - frame.origin.y - frame.size.height;
    return frame;
}
- (CGPoint) fixPoint:(CGPoint)point fromPoint:(CGSize)containerSize
{
    CGPoint frame = point;
    frame.y = size.height - frame.y;
    return frame;
}

答案 2 :(得分:1)

我希望这可以帮到你:

let frame = pathView.frame
let anchorPoint = CGPointMake(0, 1) //Set the animation direction
let position = CGPointMake(frame.origin.x + anchorPoint.x * frame.size.width, frame.origin.y + anchorPoint.y * frame.size.height)
pathView.layer.anchorPoint = anchorPoint
pathView.layer.position = position
UIView.animateWithDuration(0.8){ () -> Void in
    pathView.layer.transform = CATransform3DMakeScale(0.5, 0.5, 1)
}