首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIImageView调整尺寸和同时旋转UIImageView?

UIImageView调整尺寸和同时旋转UIImageView?
EN

Stack Overflow用户
提问于 2014-12-05 10:23:47
回答 3查看 862关注 0票数 2

我的UIImageView在我的UIViewController里。我在上面画了张照片。我做了轮换,如下所示。

代码语言:javascript
复制
- (void) runSpinAnimationOnView:(UIImageView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat
{
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
    rotationAnimation.duration = duration;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = repeat;

    [view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

}

我称之为

代码语言:javascript
复制
[self runSpinAnimationOnView:_imageView duration:1.0 rotations:360 repeat:1.0];

现在,我也想调整相同的图像视图,但从各个方面的比例相等,我如何做到这一点。

简单地说,我想旋转一个UIImageView并同时调整它的大小。

谢谢

EN

回答 3

Stack Overflow用户

发布于 2014-12-05 11:19:46

CGAffineTransformConcat将完成您的目的,这将将两个转换为一个&制作为单一动画。尝尝这个。

代码语言:javascript
复制
[UIView animateWithDuration: 3.0f
                      delay: 0
                    options: (UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
                 animations:^{

                     UIView *yourViewToBeAnimated = YourViewToBeSetHere;

                     CGAffineTransform animationToRotate = CGAffineTransformMakeRotation(45);

                     CGAffineTransform animationToScale = CGAffineTransformMakeScale(2, 2);//Double the size


                     yourViewToBeAnimated.transform = CGAffineTransformConcat(animationToScale, animationToRotate);


                 }
                 completion:^(BOOL finished) {




                 }
 ];
票数 1
EN

Stack Overflow用户

发布于 2014-12-05 10:46:03

您可以向图层添加多个动画。只需添加@"transform.scale"动画

代码语言:javascript
复制
- (void) runScaleAnimationOnView:(UIImageView*)view duration:(CGFloat)duration scale:(CGFloat)scale repeat:(float)repeat
{
    CABasicAnimation* scaleAnimation;
    scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.toValue = [NSNumber numberWithFloat: scale];
    scaleAnimation.duration = duration;
    scaleAnimation.repeatCount = repeat;

    [view.layer addAnimation:rotationAnimation forKey:@"scaleAnimation"];
}

[self runSpinAnimationOnView:_imageView duration:1.0 rotations:360 repeat:1.0];
[self runScaleAnimationOnView:_imageView duration:1.0 scale:0.5 repeat:1.0];

注意,您可能还需要调整@"position"

票数 0
EN

Stack Overflow用户

发布于 2014-12-05 11:26:13

只需这样做,您就可以按比例制作CGRectMake,这是您想要的。这只是显示它将如何调整大小的方式。

代码语言:javascript
复制
- (void)rotateSpinningView
    {

        _imageView.frame = CGRectMake(_imageView.frame.origin.x+5,
                                      _imageView.frame.origin.y+5,
                                      _imageView.frame.size.width-10,
                                      _imageView.frame.size.height-10);

        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        _imageView.clipsToBounds = YES;


        [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
            [_imageView setTransform:CGAffineTransformRotate(_imageView.transform, M_PI_2)];
        } completion:^(BOOL finished) {
            if (finished && !CGAffineTransformEqualToTransform(_imageView.transform, CGAffineTransformIdentity)) {
                [self rotateSpinningView];
            }
        }];
    }

    - (IBAction)changeView:(UIButton *)sender {

        [self rotateSpinningView];

    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27313702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档