【问题标题】:how to Zoom image using CABasicanimation如何使用 CABasicanimation 缩放图像
【发布时间】:2023-03-12 22:19:01
【问题描述】:
[UIView animateWithDuration:0.5 animations:^{
    imageView.frame = self.view.bounds;

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

如何使用 CABasicanimation 编写此内容。

【问题讨论】:

    标签: objective-c uiimageview cabasicanimation


    【解决方案1】:

    下面是简单的实现

    -(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;
        }
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2023-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多