簡體   English   中英

UISnapBehavior導致失真

[英]UISnapBehavior Causing Distortion

無論出於何種原因,無論何時我使用捕捉行為,當“捕捉”時,都會導致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來解決了此問題)。

我想解決此問題的方法是:為要制作動畫的對象制作快照圖像; 隱藏實際對象並將快照圖像放置在它們的位置; 為快照圖像制作動畫; 當結束時,將快照圖像移出界面,並在其新位置顯示實際對象。

這是可行的,因為快照圖像不受自動布局的約束。 但是,您仍然需要解決這個問題,因為您無法通過設置按鈕的frame來移動受“自動布局”控制的按鈕; 您必須設置他們的約束

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM