I'm attempting to animate a view into position in a view that's using UIDynamics. I'm not clear on the interaction between the Core Animation animations and UIDynamics but something's going on that I don't understand.
I have a test project with a view controller with a single view, a label, that starts at the bottom middle of the view and I'm trying to animate motion to the top middle.
// Create the label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(160, 400, 100, 50)];
label.text = @"hello";
[self.view addSubview:label];
// Set up the animator and collision
self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
UICollisionBehavior *collisionBehaviour = [[UICollisionBehavior alloc] initWithItems:@[ label ]];
[collisionBehaviour addBoundaryWithIdentifier:@"wall"
fromPoint:CGPointMake(0, 50)
toPoint:CGPointMake(320, 50)];
[self.animator addBehavior:collisionBehaviour];
// Animate the label
[UIView animateWithDuration:1.0
animations:^{
label.frame = CGRectMake(160, 100, 320, 100);
}];
This is simply a line boundary at the top of the view, nowhere near either the start or end position of my animation. I don't see why it should affect the animation of the button into its initial position, but it does.
If I comment out the addBehaviour: call then the animation works fine. But when I add the behaviour, the animation goes to the wrong location. I don't understand why.