繁体   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