簡體   English   中英

UIDynamicAnimator順序動畫

[英]UIDynamicAnimator sequential animation

我正在嘗試使按鈕從菜單按鈕中彈出(類似於Path上的+按鈕),並使用UIDynamicAnimator設置捕捉和退出按鈕的動畫。 它有效並且代碼非常簡單。

    _animator = [[UIDynamicAnimator alloc] initWithReferenceView:sender.superview];

    UIDynamicItemBehavior *resistance = [[UIDynamicItemBehavior alloc] initWithItems:@[_cartBtn, _chatBtn, _eventBtn]];
    resistance.resistance = 5.0f;
    [_animator addBehavior:resistance];

    CGFloat radius = 75;
    CGPoint target = sender.center;
    target.x += radius * cos(GLKMathDegreesToRadians(265));
    target.y += radius * sin(GLKMathDegreesToRadians(265));
    UISnapBehavior *snapBehavior = [[UISnapBehavior alloc] initWithItem:_cartBtn snapToPoint:target];
    [_animator addBehavior:snapBehavior];

    target = sender.center;
    target.x += radius * cos(GLKMathDegreesToRadians(225));
    target.y += radius * sin(GLKMathDegreesToRadians(225));
    UISnapBehavior *snapBehavior2 = [[UISnapBehavior alloc] initWithItem:_chatBtn snapToPoint:target];
    [_animator addBehavior:snapBehavior2];

    target = sender.center;
    target.x += radius * cos(GLKMathDegreesToRadians(185));
    target.y += radius * sin(GLKMathDegreesToRadians(185));
    UISnapBehavior *snapBehavior3 = [[UISnapBehavior alloc] initWithItem:_eventBtn snapToPoint:target];
    [_animator addBehavior:snapBehavior3];

這樣,所有三個按鈕會同時彈出。 我想問的是,是否可以使用UIDynamicAnimator使按鈕一個接一個地動畫,或者其他簡單的方法?

顯然我只需要添加一個很小的延遲,例如[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 之間addBehavior:

暫無
暫無

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

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