UIImageView使用动画块从中心进行缩放

12

我正在使用以下代码将图像进行放大,但它是从左上角开始缩放的,如何让它从中心点开始缩放?

[UIView animateWithDuration:duration delay:delay options:options 
                 animations:^{
                     myImageView.frame = frame;
                     myImageView.alpha = alpha;
                 }
                 completion:^(BOOL finished) {

                 }
 ];
3个回答

36
[UIView animateWithDuration:0.5 
                      delay:0
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:(void (^)(void)) ^{
                     myImageView.transform=CGAffineTransformMakeScale(1.2, 1.2);
                 }
                 completion:^(BOOL finished){
                     myImageView.transform=CGAffineTransformIdentity;
                 }];

这将完美地运作。
祝你好运!


1
这在iOS 7.1下仍然从左侧进行缩放。我无法弄清楚我做错了什么。也许是自动布局? - devios1

3

试试这个:

[UIView animateWithDuration:2
   animations:^{
       float zoomScal = 5; //want 5x zoom
       CGPoint CenterPoint = CGPointMake(200, 300); // want center point to this
       imgArtifactImage.frame = CGRectMake(- CenterPoint.x * (zoomScal-1),- CenterPoint.y * (zoomScal-1),self.view.frame.size.width * zoomScal,self.view.frame.size.height * zoomScal);
} completion:^(BOOL finished){}];

对我来说它是有效的。


1
也许需要在结尾加上 ];。 - Doug Null

2

这可以是放大图像的动画块

在这里,您可以使用uiimageview视图

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:GROW_ANIMATION_DURATION_SECONDS];
theView.transform = CGAffineTransformMakeScale(1.2, 1.2);

[UIView commitAnimations];

嗨,谢谢回答,但我正在寻找一种使用动画块的新SDK 4技术方面的答案。 - user689751

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接