视图的动画大小保持其左下角固定

时间:2013-07-08 08:53:15

标签: ios objective-c uiview uiviewanimation

我的UIView左下角有superview,即框架就像

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

我想设置其大小的动画,使其左下角保持固定在其位置。我不知道如何使用图层的锚点属性。 目前我正在使用以下代码行增加其大小。

[UIView animateWithDuration:0.2 animations:^{


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

这种方法很好但是当我尝试恢复到原来的大小时,它的底点会在动画开始时被提升并在动画结束时稳定下来。

1 个答案:

答案 0 :(得分:0)

首先定义左下角的点...

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

然后你需要定义尺寸(大小)。

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

然后为它们制作动画......

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

只要您设置了帧并且计算出的结束帧是正确的并且它们都在一个动画中完成,那么左下角将不会移动。

如果这没有帮助,请发布一个视频,了解正在发生的事情(以及所有动画代码)。

修改

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