gpt4 book ai didi

ios - UISnapBehavior 导致失真

转载 作者:行者123 更新时间:2023-11-29 03:03:51 24 4
gpt4 key购买 nike

无论出于何种原因,每当我使用捕捉行为时,它都会导致 UIButton 在“捕捉”时变成各种大小的矩形。我可能只是在看这个问题。我的最后期限是明天,以解决最后的错误,所以我将不胜感激任何帮助!谢谢!

vvv - ViewController.m - vvv

//set points
CGPoint bullyboxPoint = {80, 188};
CGPoint weemPoint = {240, 188};
CGPoint yeaPoint = {80, 339};
CGPoint charityPoint = {240, 339};
CGPoint phhsPoint = {80, 488};
CGPoint experiencePoint = {240, 488};

//make the buttons closer to speed up the snap
bullybox.frame = CGRectMake(40, 788, 120, 120);
weem.frame = CGRectMake(200, 788, 120, 120);
yea.frame = CGRectMake(30, 939, 120, 120);
charity.frame = CGRectMake(190, 939, 120, 120);
phhs.frame = CGRectMake(20, 1328, 120, 120);
experience.frame = CGRectMake(180, 1328, 120, 120);

//create behaviors
UISnapBehavior *snapBehavior = [[UISnapBehavior alloc] initWithItem:self->bullybox snapToPoint:bullyboxPoint];
UISnapBehavior *snapBehavior1 = [[UISnapBehavior alloc] initWithItem:self->weem snapToPoint:weemPoint];
UISnapBehavior *snapBehavior2 = [[UISnapBehavior alloc] initWithItem:self->yea snapToPoint:yeaPoint];
UISnapBehavior *snapBehavior3 = [[UISnapBehavior alloc] initWithItem:self->charity snapToPoint:charityPoint];
UISnapBehavior *snapBehavior4 = [[UISnapBehavior alloc] initWithItem:self->phhs snapToPoint:phhsPoint];
UISnapBehavior *snapBehavior5 = [[UISnapBehavior alloc] initWithItem:self->experience snapToPoint:experiencePoint];

//dampen the snap
snapBehavior.damping = 1.2f;
snapBehavior1.damping = 1.2f;
snapBehavior2.damping = 1.2f;
snapBehavior3.damping = 1.2f;
snapBehavior4.damping = 1.2f;
snapBehavior5.damping = 1.2f;

//add behaviors
[self.animator addBehavior:snapBehavior];
[self.animator addBehavior:snapBehavior1];
[self.animator addBehavior:snapBehavior2];
[self.animator addBehavior:snapBehavior3];
[self.animator addBehavior:snapBehavior4];
[self.animator addBehavior:snapBehavior5];

最佳答案

问题可能是您正在使用自动布局。 Autolayout 和 UIKit Dynamics 是敌人(如果你看一下 Apple 的示例代码,你会发现他们通过关闭 Autolayout 规避了这个问题)。

我喜欢解决这个问题的方法是:制作要动画的对象的快照图像;隐藏实际对象并将快照图像放在其位置;对快照图像进行动画处理;一切结束后,将快照图像从界面中取出并在新位置显示实际对象。

这是有效的,因为快照图像不受自动布局的影响。但是,您仍然需要解决这个问题,因为您无法通过设置其框架来移动受自动布局约束的按钮;您必须设置他们的约束

关于ios - UISnapBehavior 导致失真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23000440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com