UISnapBehavior导致失真

时间:2014-04-10 22:47:14

标签: ios objective-c

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

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

1 个答案:

答案 0 :(得分:1)

问题可能是你正在使用Autolayout。 Autolayout和UIKit Dynamics是敌人(如果你看看Apple的示例代码,你会看到他们通过关闭Autolayout来规避这个问题。)

我想解决这个问题的方法是:制作动画对象的快照图像;隐藏实际对象并将快照图像放在其位置;动画快照图像;当它全部结束时,将快照图像从界面中取出并在新位置显示实际对象。

这是有效的,因为快照图像不受Autolayout的限制。但是,仍然需要解决问题,因为您无法通过设置frame移动受Autolayout影响的按钮;您必须设置约束