UIImageView scale from center using Animation Bloc

2019-03-18 17:19发布

问题:

I am using the following to scale image up but it's scaling from it's left top point, how can I make the scale from center

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

                 }
 ];

回答1:

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

this will work perfectly
Good Luck



回答2:

Try this:

[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){}];

It's working for me.



回答3:

this can be the block of animation for the scale up the image

here as theView U Can Use the uiimageview

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

[UIView commitAnimations];