视图具有重力效果时的奇怪动画。
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];
- 菜单打开。
- 奇怪的(据说是 UIGravityBehavior)动画。(0.5-1秒白色条纹停留在左侧
- 白色条纹消失在:
- (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];
}
}
}