There are animation elements (Label, Button, TextField) using UIDynamicAnimator, etc. After the animation, all the elements "roll" below at different angles. How to make their return to the original place, as it was before the animation?

@interface ViewController () { UIDynamicAnimator *animatir; UIGravityBehavior *gravity; UICollisionBehavior *collision; UIDynamicItemBehavior *bounce; } @end 

. . .

 -(IBAction) buttonPressed: (id) sender { animatir = [[UIDynamicAnimator alloc]initWithReferenceView:self.view]; gravity = [[UIGravityBehavior alloc] initWithItems: @[label1, label2, label3, Edit1, Ediit2, Button2]]; [animatir addBehavior:gravity]; collision = [[UICollisionBehavior alloc]initWithItems:@[label1, label2, label3, Edit1, Ediit2, Button2]]; collision.translatesReferenceBoundsIntoBoundary = YES; [animatir addBehavior:collision]; bounce = [[UIDynamicItemBehavior alloc]initWithItems:@[label1, label2, label3, Edit1, Ediit2, Button2]]; bounce.elasticity = 0.90; [animatir addBehavior:bounce]; } 

Closed due to the fact that off-topic participants are Visman , Aries , ermak0ff , Mstislav Pavlov , Vladimir Glinskikh 3 Oct '15 at 3:52 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Visman, Aries, ermak0ff, Mstislav Pavlov, Vladimir Glinskikh
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • I propose to close as resolved. The vehicle apparently logged in under a different account, so the password does not remember from this. - Visman

1 answer 1

As far as I know, UIKitDynamics is not responsible for storing the state history of objects.

If Autolayout is used, then the status can be returned quite simply.

 - (void)resetToInitialState { NSArray *objects = @[self.label1, self.label2, self.label3, self.textField1, self.textField2, self.button]; // Очищаем все behavior у аниматора [self.animator removeAllBehaviors]; // Обновляем layout [self.view setNeedsLayout]; // Далее отменяем все трансформации. Если этого не сделать, то все вьюшки будут повернуты [objects enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL * _Nonnull stop) { view.transform = CGAffineTransformIdentity; }]; } 

If without Autolayout, then you need to save the frame parameter of all objects and then return the values ​​when returning.