Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 设置视图大小的动画,保持其左下角点固定_Ios_Objective C_Uiview_Uiviewanimation - Fatal编程技术网

Ios 设置视图大小的动画,保持其左下角点固定

Ios 设置视图大小的动画,保持其左下角点固定,ios,objective-c,uiview,uiviewanimation,Ios,Objective C,Uiview,Uiviewanimation,我在其超级视图的左下角有一个ui视图,即其框架如下 [myView setFrame:CGRectMake(0,superView.bounds.size.height-myViewHeight,myViewWidth,myViewHeight)]; 我希望设置其大小的动画,使其左下角点保持固定在其位置。我不知道如何使用层的锚点属性。 目前,我正在使用以下代码行增加其大小 [UIView animateWithDuration:0.2 animations:^{ [

我在其
超级视图的左下角有一个
ui视图
,即其框架如下

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

这很好,但当我尝试恢复到其原始大小时,其底部点在动画开始时被提升,并在动画结束时稳定下来。

首先定义左下角的点

CGPoint bottomLeft = CGPointMake(0, 480); // this 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];

不,它没有帮助…这样做,它可以在大尺寸的情况下正确地设置动画,但是当设置回小尺寸的动画时,它的尺寸仅在动画开始时获得等效的小尺寸,并且在动画过程中仅其帧设置动画。我将上传一个视频,使其更清晰,直到同样,它的大小在动画开始时缩小到小尺寸,然后它的位置在整个持续时间内设置动画。它的层设置了正确的动画,而层内的视图在动画开始时缩小。我怀疑bottomLbl是一个UILabel。如果是这种情况,则无法设置边界的动画,并期望文本正确设置动画。文本将立即以最终大小绘制,标签的边界将设置动画。您可能需要在此处使用缩放变换。是的,我们无法设置UILabel边界的动画。我用UITextView来解决我的问题。这是UILabel的一些内容重力问题..:p此处有更多详细信息
[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];