user689751
user689751

Reputation:

UIImageView scale from center using Animation Blocks

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) {

                 }
 ];

Upvotes: 12

Views: 17137

Answers (3)

Hardik Darji
Hardik Darji

Reputation: 3684

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.

Upvotes: 3

NIKHIL
NIKHIL

Reputation: 2719

[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

Upvotes: 36

NIKHIL
NIKHIL

Reputation: 2719

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];

Upvotes: 2

Related Questions