0

My button has a constraint that it should center horizontally in the superview. I tried to just change my constraint but nothing happens. My idea is that I move my button to the side and then back and add a springy automation.

- (void)shakeView {
    NSLog(@"Shake it baby!");
    NSUInteger centerDefault = self.loginButtonHorizontalCenterConstraint.constant;
    self.loginButtonHorizontalCenterConstraint.constant = centerDefault + 50;

    [self.view layoutIfNeeded];
    //  self.signInContainerCenterPosition = constraint
    self.loginButtonHorizontalCenterConstraint.constant = centerDefault;

    [self.view setNeedsUpdateConstraints];
    [UIView animateWithDuration:1.5 delay:0.0 usingSpringWithDamping:0.1 initialSpringVelocity:40 options:UIViewAnimationOptionCurveLinear animations:^{

        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {


    }];
}

So, I got two questions. Why can't I move my button to the side with 50px and is this a viable way to get my uibutton to shake?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sebastian L
  • 924
  • 2
  • 10
  • 20

0 Answers0