UIView animation and save a corner radius as a circle

I have a UIView circle:

con=[[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width-size-delta, y , size, size)]; con.layer.borderColor=[UIColor whiteColor].CGColor; con.layer.borderWidth=1.0; con.backgroundColor=[UIColor clearColor]; con.layer.cornerRadius=con.frame.size.width/2.0; con.clipsToBounds=YES; [self addSubview:con]; 

Later I would like to change its size to a larger one, but when I do this, at the beginning of the animation you will see some rectangular shape, and then change it to a circle.

I need a flat animation where it will stay around when its frame changes.

  CGRect frm=startConfrm; //original frame of the circle frm.size.width*=2; frm.size.height*=2; frm.origin.y=self.frame.size.height/2.0-frm.size.height/2.0; [UIView animateWithDuration:1.5 delay:0.0 options: UIViewAnimationOptionCurveEaseInOut animations:^{ con.frame=frm; con.layer.cornerRadius=con.frame.size.width/2.0; } completion:^(BOOL finished){ }]; 
+5
source share
2 answers

If you want to scale the size of your view, you can use the code below.

 [UIView animateWithDuration:2.0 animations:^{ con.transform = CGAffineTransformMakeScale(2, 2); // it will scale as double size }completion:^(BOOL finished) { // do whatever at animation completion } }]; 

In reset, view the normal size,

con.transform = CGAffineTransformIdentity;

Link: https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGAffineTransform/index.html#//apple_ref/c/func/CGAffineTransformMakeScale

+7
source

To pretend to β€œgrow” in place, do not animate the frame. Animate the transformation.

Load your sub-tier from the tip. Set its conversion to scale 0:

 view.transform = CGAffineTransformMakeScale(1,1); 

Then add it to your supervisor.

Inside the animation block, set the value for the conversion:

 view.transform = CGAffineTransformIdentity; 

And the performance will grow to a normal size. You may need to bother with the anchor point to make it grow from the right point.

You can also change the frame inside the block, but for moving only I prefer to change the property of the center, you should not try to set the frame if you also have a transformation.

Hope this helps you!

EDIT: Replace the animation block code with the following code:

 [UIView animateWithDuration:1.5 delay:0.0 options: UIViewAnimationOptionCurveEaseInOut animations:^{ CGAffineTransform newTransform; newTransform = CGAffineTransformMakeScale(0, 0); con.transform = CGAffineTransformScale(newTransform,2,2); } completion:^(BOOL finished){ }]; 
+4
source

All Articles