iPad - 如何移动标签和调整标签大小

发布于 2024-10-31 01:44:10 字数 1245 浏览 1 评论 0原文

我正在尝试移动标签并调整其大小,但发生的情况是标签立即调整大小然后移动到位。我首先尝试了注释掉的 lbl.frame 行。接下来我发现了这个问题:

How to animate while resizing UIView

并添加了所有除 contentMode 之外的其他代码。这达到了我想要的效果,但是标签的字体没有随着标签缩小而向下调整。 (我勾选调整以适应 xib )。最后添加 contentMode 行给了我与原始框架行相同的结果 - 首先立即缩小它们为移动设置动画。

    lbl.contentMode = UIViewContentModeRedraw;
    [UIView animateWithDuration:1.0 delay:0.0
                        options:(UIViewAnimationOptionAllowUserInteraction)
                     animations:^{
                         //lbl.frame = CGRectMake(x, mStartingLine.frame.origin.y+mStartingLine.frame.size.height, 100, 100);
                         CGRect theBounds = lbl.bounds;
                         CGPoint theCenter = lbl.center;
                         theBounds.size.height = 100;
                         theBounds.size.width = 100;
                         theCenter.y = mStartingLine.frame.origin.y+mStartingLine.frame.size.height+50;
                         theCenter.x = x;
                         lbl.bounds = theBounds;
                         lbl.center = theCenter;
                     }
                     completion:nil
     ];

I'm trying to move and resize a label, but what happens is the label resizes immediately then moves into position. I first tried simply the commented out lbl.frame line. Next I found this question:

How to animate while resizing UIView

And added all the other code except for the contentMode. This did what I wanted, but the Label's font did not adjust downwards as the label shrunk. ( I tick adjust to fit in xib ). Finally adding the contentMode line gave me the same result as my original frame line - shrink immediately first them animate the move.

    lbl.contentMode = UIViewContentModeRedraw;
    [UIView animateWithDuration:1.0 delay:0.0
                        options:(UIViewAnimationOptionAllowUserInteraction)
                     animations:^{
                         //lbl.frame = CGRectMake(x, mStartingLine.frame.origin.y+mStartingLine.frame.size.height, 100, 100);
                         CGRect theBounds = lbl.bounds;
                         CGPoint theCenter = lbl.center;
                         theBounds.size.height = 100;
                         theBounds.size.width = 100;
                         theCenter.y = mStartingLine.frame.origin.y+mStartingLine.frame.size.height+50;
                         theCenter.x = x;
                         lbl.bounds = theBounds;
                         lbl.center = theCenter;
                     }
                     completion:nil
     ];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别想她 2024-11-07 01:44:10

我怀疑自动文本调整大小功能不适用于核心动画。

我建议做的是将标签设置为其最终大小(使用其边界),然后对其应用变换,将其缩小回其起始大小。这些东西的最终效果是它应该保持相同的外观尺寸。

最后,使用 animateWithDuration:animations: 将视图的变换设置回恒等变换,以便它增长到新的大小。

我不知道这会导致什么绘图伪影 - 你必须尝试一下。

I suspect that the auto text resizing feature doesn't work with Core Animation.

What I would suggest doing is to set the label to it's final size (using it's bounds) then apply a transform to it that shrinks it back down to it's starting size. The end effect of those things is that it should stay at the same apparent size.

Finally, use animateWithDuration:animations: to set the view's transform back to the identity transform, so it grows to it's new size.

I don't know what drawing artifacts this will cause - you'll have to try it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文