Search code examples
animationuiviewtransformzoomingios9.1

Zoom out center UIView animation


I have a UIView in my viewcontroller. It has frame (34,250,253,193) and it is the center horizontally. I want to zoom in and zoom out this UIView. With Zoom in, it works fine with center. However with Zoom out, it works incorrect. Currently,the view zoom out from right to left. I don't want this. I want it zoom out with center.

This is my code

-(void)zoomin:(UIView*)view {
   view.transform = CGAffineTransformMakeScale(0.1,0.1);
   [UIView animateWithDuration:2.0 animations: ^{
      view.transform = CGAffineTransformMakeScale(1,1);
   }];
}

-(void)zoomout:(UIView*)view {
   view.transform = CGAffineTransformMakeScale(1,1);
   [UIView animateWithDuration:2.0 animations: ^{
      view.transform = CGAffineTransformMakeScale(0.1,0.1);
   }];
} 

Solution

  • The problem is that your code, as far as you have shown it, works perfectly:

    enter image description here

    It therefore follows logically that if there's a problem, it is caused by something you have not shown. But since you have not shown it, there is no way of knowing what it is (aside from guessing).