weird UIDynamicAnimator/UIGravityBehavior animation

362 views Asked by At

strange animation when view has a gravity effect.

CGFloat t = self.contentView.frame.origin.x;
CGFloat centerEdge = self.view.frame.size.width/2.0f;
CGPoint velocity = [gesture velocityInView:self.view];

CGPoint point = CGPointMake(movingView.frame.origin.x + translation.x + velocity.x, movingView.frame.origin.y);

collisionBehaviour = [[UICollisionBehavior alloc] initWithItems:@[self.contentView]];
collisionBehaviour.translatesReferenceBoundsIntoBoundary = NO;
collisionBehaviour.collisionDelegate = self;

UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width+self.menuSize, self.view.bounds.size.height)];
[collisionBehaviour addBoundaryWithIdentifier:@"rect" forPath:path];

pushBehavior = [[UIPushBehavior alloc] initWithItems:@[self.contentView] mode:UIPushBehaviorModeContinuous];
pushBehavior.pushDirection = CGVectorMake(velocity.x, 0.0f);
pushBehavior.active = YES;

elasticityBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[self.contentView]];
elasticityBehavior.elasticity = 0.4f;
elasticityBehavior.allowsRotation = NO;

gravityBehavior = [[UIGravityBehavior alloc] initWithItems:@[self.contentView]];
if (t < centerEdge) {
    gravityBehavior.gravityDirection = CGVectorMake(-1.0f, 0.0f);
} else {
    gravityBehavior.gravityDirection = CGVectorMake(1.0f, 0.0f);
}

[animator addBehavior:collisionBehaviour];
[animator addBehavior:pushBehavior];
[animator addBehavior:elasticityBehavior];
[animator addBehavior:gravityBehavior];

example

  1. Menu is opened.
  2. Weird (supposedly UIGravityBehavior) animation. (0.5-1 second white stripe stay on the left side
  3. White stripe disappear in:
- (void)dynamicAnimatorDidPause:(UIDynamicAnimator *)a{
    if ([animator.behaviors count] > 0) {
        [self removeAnimation];

        CGFloat t = self.contentView.frame.origin.x;
        CGFloat centerEdge = self.view.frame.size.width/2.0f;

        if (t < centerEdge) {
            [self slideInAnimated:YES completion:nil]; // Change origin to CGPointZero
        } else {
            [self slideToSideAnimated:YES completion:nil];
        }
    }
}
0

There are 0 answers