0

I've been digging through some UIDynamics examples and I've checked out some of the WWDC videos, but I'm still a bit lost on how I'd replicate that bounce on the lock screen. I'd like to "bounce" the contentView of a UIView on tap. There's a swipe gesture when you can push up to reveal a button drawer but, I'd like to integrate some UIDynamics. Also, how would I set the boundaries of the UIDynamics behavior? The contentView would need to lock into place when the user has swiped up a certain distance. Thanks for any tips.

STANGMMX
  • 973
  • 7
  • 18
  • 31
  • Are you talking about on the lock screen how you click the camera, drag up half way, let it go, and it bounces off the bottom? – Peter Foti Nov 13 '13 at 15:52
  • Yes, that and how if you just tap it, it bounces. Except the drag up is not the span of the screen. – STANGMMX Nov 13 '13 at 16:26

1 Answers1

1

I don't have a project to work on this with but the following will take a UIButton and when you click on it, drop it to the bottom of the view, and it will bounce.

- (UIDynamicAnimator *)animator
{
    if (!_animator) {
        _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
    }

    return _animator;
}

- (IBAction)clicked:(id)sender {
    UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[self.button1]];
    UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:@[self.button1]];
    collision.translatesReferenceBoundsIntoBoundary = YES;
    [self.animator addBehavior:collision];
    [self.animator addBehavior:gravity];
}
Peter Foti
  • 5,526
  • 6
  • 34
  • 47
  • Okay, so to get the 'bounce', could I do something like a UIView animateWithDuration and raise the contentView up a few pixels? Since It's given an gravity behavior I guess it would drop down? And how do I set the bounds for how far it can drop? I wouldn't want it to drpo off screen. – STANGMMX Nov 13 '13 at 19:54