0

I'm building an app where I want a kind of reverse pull-to-refresh. There's no tableView involved but I would like to pull a UIButton to increase it's height and animate the label and other properties like the backgroundColor simultaneously - achieving the same effect seen with pull-to-refresh. I also need that rebound/bounce effect to emulate gravity.

A very good example of the desired behaviour is the iOS action center

One idea was to link the animateWithDuration of UIView up to a UIGestureRecognizer:

[UIView animateWithDuration: delay: usingSpringWithDamping: initialSpringVelocity: options: animations: completion:nil]

I'm using storyboards and autolayout. What would be the best approach to this?

Thanks!

Erik
  • 799
  • 2
  • 15
  • 27

1 Answers1

0

You need to use the height constraint of your button.

If you don't have any reference to it, you can control-drag it to your ViewController, Like so

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *buttonHeight;

Once you have this you can change the buttons height according to the user pan gesture. Just add the gestureRecogniser to the View

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(userPulledDown:)];
[view addGestureRecognizer:pan];

in the gesture method

- (void)userPulledDown:(UIGestureRecognizer *)gesture
{
  switch (gesture.state){
    case UIGestureRecognizerStateBegan:
       // the user has started to pull the view
       break;
    case UIGestureRecognizerStateChanged:
       // create the animation of the button (using the constraint) & other views
       break;
    case UIGestureRecognizerStateEnded:
       // clean-up after the user released the gesture
       break;
  }
}

EDIT

You i would recommend calling the method translationInView: in UIPanGestureRecognizer this method returns a CGPoint (x,y) of the panGesture in the view you gave it.

But you really need to read the documentation of UIPanGestureRecognizer & UIGestureRecognizer to really understand and to get better at coding in iOS

EDIT2

Bounce effect

check out this answer

Community
  • 1
  • 1
YYfim
  • 1,402
  • 1
  • 9
  • 24
  • I'm getting the error: Use of undeclared identifier 'Began' - do I need to import something or conform to something? – Erik Feb 13 '15 at 16:39
  • what property off the UIGestureRecognizer should I use to change the constant property of a constraint? – Erik Feb 13 '15 at 16:46
  • check out my edit, like i said check the docs in the link i gave you. This will help you – YYfim Feb 13 '15 at 16:58
  • I've read it but I don't see the full picture and I don't know how to go about creating that bounce effect – Erik Feb 13 '15 at 17:11