如何使用CABasicanimation缩放图像

时间:2016-11-12 07:16:16

标签: objective-c uiimageview cabasicanimation

[UIView animateWithDuration:0.5 animations:^{
    imageView.frame = self.view.bounds;

} completion:^(BOOL finished) {}];

如何使用CABasicanimation编写此内容。

2 个答案:

答案 0 :(得分:0)

下面的

是简单的实现

-(void)StartAnmation {
          [subview.layer addAnimation:[self ZoomAnimation] forKey:@"Zoom"];
}

-(CAAnimationGroup *)ZoomAnimation {
    CAAnimationGroup *ZoomAnimation = [CAAnimationGroup animation];
    CABasicAnimation *In = [self zoomIn];
    ZoomAnimation.animations = [NSArray arrayWithObjects: In, nil];
    ZoomAnimation.duration = 2.0f;
    return ZoomAnimation;
}

    -(CABasicAnimation *)zoomIn {
CABasicAnimation *ZoomInAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
        ZoomInAnimation.beginTime = 0.0f;
        ZoomInAnimation.fromValue = [NSNumber numberWithFloat:20.0];
        ZoomInAnimation.toValue = [NSNumber numberWithFloat:1.0];
        ZoomInAnimation.duration = 2.0f;
        return ZoomInAnimation;
    }

答案 1 :(得分:0)

对于缩放图像,您可以使用UIImageView本身完成。

请参阅答案Pinch To Zoom Effect on UIImageView inside scrollView