Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CALayer scale animation for layer size starting from bottom left to top right

Tags:

ios

ios4

ios5

Another problem with animation on a layer to make it scale and show like growing from bottom left, somewhat similar to the figure :

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

I have tried some animations but not able to achieve it exactly the way i want. Please suggest. Currently using following code to scale:

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];
like image 945
Amit Avatar asked Mar 23 '12 10:03

Amit


3 Answers

You should set a different anchorPoint to acheive that effect.

    layer.anchorPoint = CGPointMake(0.0f, 1.0f);
like image 109
Kostia Dombrovsky Avatar answered Nov 15 '22 09:11

Kostia Dombrovsky


I hope this can help you:

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)
}
like image 36
mokai Avatar answered Nov 15 '22 09:11

mokai


All of this doesn't work for me. Methods that fixing frames and points

- (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;
}
like image 36
Tim Kozak Avatar answered Nov 15 '22 09:11

Tim Kozak