无论出于什么原因,每当我使用抓取行为时,它都会导致UIButtons在“剪贴”时变成各种大小的矩形。我可能只是在仔细考虑这个问题。我的最后期限是明天,让最后的错误解决,所以我将非常感谢任何帮助!谢谢!
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];发布于 2014-04-10 23:44:40
问题可能是你在使用Autolayout。Autolayout和UIKit Dynamics是敌人(如果你看一下苹果的示例代码,你会发现他们通过关闭Autolayout来绕过这个问题)。
我喜欢解决这个问题的方法是:使对象的快照图像动画化;隐藏实际对象并将快照图像放在它们的位置;将快照图像动画化;当快照图像全部结束时,将快照图像从接口中取出,并在它们的新位置显示实际对象。
这是因为快照图像不受Autolayout的约束。但是,您仍然需要解决这个问题,因为您不能通过设置其frame来移动受Autolayout约束的按钮;您必须设置它们的约束。
https://stackoverflow.com/questions/23000440
复制相似问题