Custom keyboard height animation in iOS 8

I am trying to increase the height of a custom keyboard in an animation with the following code. But I can’t understand why the change happens instantly, ignoring the animation.

//In viewDidAppear [self.view needsUpdateConstraints]; [UIView animateWithDuration:2 animations:^{ CGFloat _expandedHeight = 500; NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint constraintWithItem: self.view attribute: NSLayoutAttributeHeight relatedBy: NSLayoutRelationEqual toItem: nil attribute: NSLayoutAttributeNotAnAttribute multiplier: 0.0 constant: _expandedHeight]; [self.view addConstraint: _heightConstraint]; [self.view layoutIfNeeded]; }]; 
+5
source share
3 answers

First add contraindications outside the animation block, then call updateConstraints and inside the animation block, call layoutIfNeeded. Streamline it will

  CGFloat _expandedHeight = 500; NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint constraintWithItem: self.view attribute: NSLayoutAttributeHeight relatedBy: NSLayoutRelationEqual toItem: nil attribute: NSLayoutAttributeNotAnAttribute multiplier: 0.0 constant: _expandedHeight]; [self.view addConstraint: _heightConstraint]; [self.view needsUpdateConstraints]; [UIView animateWithDuration:2 animations:^{ [self.view layoutIfNeeded]; }]; 
0
source

Below is the code that I use to animate the position of the X center of the line. I connected the center X of this line with some center view link using IBOutlet NSLayoutConstraint. Inorder for animations that occur during auto-detection, you must update the constraint and call layoutIfNeeded inside the animation block. This is definitely an autoplay animation idea.

  blueScrollerCenterXConstraint.constant = (btn.tag - 4000)*btn.frame.size.width; [blueScroller updateConstraints]; [UIView animateWithDuration:0.3 animations:^{ [blueScroller layoutIfNeeded]; }]; 
0
source
  • You should not add a restriction.

  • Add it and turn it off (or set the priority to really very low).

  • After that, change the priority to 999 and run layoutIfNeded in the animation block.

0
source

Source: https://habr.com/ru/post/1204771/


All Articles