我剛開始使用UIDynamic套件,並且已在線跟蹤示例。我已經達到了我想要的行爲,這是爲了在一個方向上獲得瞬間的力量並且回到原來的位置。具有附件和推送行爲的UIDynamicKit會導致較長的振盪時間
我實現這一點使用下面
CGPoint origCenter = self.viewContentContainer.center;
self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
UIPushBehavior *push = [[UIPushBehavior alloc]
initWithItems:@[self.viewContentContainer] mode:UIPushBehaviorModeInstantaneous];
CGVector vector = CGVectorMake(200.0, 0.0);
push.pushDirection = vector;
CGPoint anchorpoint = origCenter;
UIAttachmentBehavior *attachment = [[UIAttachmentBehavior alloc] initWithItem:self.viewContentContainer attachedToAnchor:anchorpoint];
[attachment setFrequency:2.0];
[attachment setDamping:0.5];
[self.animator addBehavior:push];
[self.animator addBehavior:attachment];
然而的代碼,它振盪在結束超過1或2個像素的時間很長。改變頻率和阻尼值似乎並沒有使這個更好或更糟。
有沒有其他人經歷過這個?
很多謝謝。
我有這個問題,1.0的長度似乎首先延遲振盪,但不是永遠。最終在足夠的動作之後,觀點仍然會振盪。 – snakeoil