1

I have a UIView at the bottom left of its superview, i.e.its frame is like

[myView setFrame:CGRectMake(0,superView.bounds.size.height-myViewHeight,myViewWidth,myViewHeight)];

I want to animate its size such that its bottom left point remains fixed at its position. I am not sure how to play with anchor point property of layers. Currently I am increasing its size using the following lines of code.

[UIView animateWithDuration:0.2 animations:^{


            [bottomLbl setFrame:CGRectMake(0, bottomView.bounds.size.height-250, 300, 250)];

This works fine but when I try to bring back to its original size, its bottom point gets lifted at the start of animation and settles down at the end of animation.

Girish
  • 4,692
  • 4
  • 35
  • 55
Vishal Singh
  • 4,400
  • 4
  • 27
  • 43

1 Answers1

0

First define the point for the bottom left corner...

CGPoint bottomLeft = CGPointMake(0, 480); // this can be anything.

Then you need to define the sizes (big and small).

CGSize bigSize = CGSizeMake(280, 280);
CGSize smallSize = CGSizeMake(50, 50); // again, these can be anything.

Then animate them...

// create the rect for the frame
CGRect bigFrame = CGRectMake(bottomLeft.x, bottomLeft.y - bigSize.height, bigSize.width, bigSize.height);
CGRect smallFrame = CGRectMake(bottomLeft.x, bottomLeft.y - smallSize.height, smallSize.width, smallSize.height);

[UIView animateWithDuration:0.2
                 animations:^{
    // set the rect onto the view
    bottomLbl.frame = bigFrame;
    // or
    bottomLbl.frame = smallFrame;
}];

As long as you set the frame and the calculated end frames are correct and it's all done in one animation then the bottom left corner won't move.

If this doesn't help can you please post a video of what is happening (and all your animation code).

EDIT

[UIView animateWithDuration:0.2
                      delay:0.0
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
    // set the rect onto the view
    bottomLbl.frame = bigFrame;
    // or
    bottomLbl.frame = smallFrame;
    }
                 completion:nil];
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • no it doesnt help...by doing so, it animates properly in case of bigSize, but while animating back to smallSize, its size gets equivalent smallSize at the start of the animation only, and during the course of animation only its frame animates. I will upload a vedo to make it more clear – Vishal Singh Jul 08 '13 at 10:28
  • still the same, its size gets shrinked to smallSize at the start of animation, and then its position animates thorughout the duration. – Vishal Singh Jul 08 '13 at 10:43
  • its layer is animating properly, while the view inside the layer gets shrinked at the start of the animation – Vishal Singh Jul 08 '13 at 10:48
  • 2
    I suspect that bottomLbl is a UILabel. If this is the case, you cannot animate the bounds and expect the text to animate correctly. The text will immediately be drawn at the final size, and the bounds of the label will animate into place. You will probably want to use a scale transform here. – Tark Jul 09 '13 at 07:33
  • Yes, we can not animate the bounds of UILabel. I used UITextView instead to solve my problem. Its some contentsGravity issue with UILabel..:p more details here http://stackoverflow.com/questions/17360402/why-are-animations-on-bounds-of-an-uilabel-only-working-when-increasing-the-size?rq=1 – Vishal Singh Jul 09 '13 at 21:00