Deconflict "bottom view" layout and keyboard animations.

pull/2/head
Matthew Chen 6 years ago
parent 26237c0588
commit 97603e64cc

@ -23,6 +23,7 @@ UIInterfaceOrientationMask DefaultUIInterfaceOrientationMask(void)
@property (nonatomic, weak) UIView *bottomLayoutView; @property (nonatomic, weak) UIView *bottomLayoutView;
@property (nonatomic) NSLayoutConstraint *bottomLayoutConstraint; @property (nonatomic) NSLayoutConstraint *bottomLayoutConstraint;
@property (nonatomic) BOOL shouldAnimatedBottomLayout;
@end @end
@ -64,6 +65,22 @@ UIInterfaceOrientationMask DefaultUIInterfaceOrientationMask(void)
return self; return self;
} }
#pragma mark - View Lifecycle
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.shouldAnimatedBottomLayout = YES;
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
self.shouldAnimatedBottomLayout = NO;
}
- (void)viewDidLoad - (void)viewDidLoad
{ {
[super viewDidLoad]; [super viewDidLoad];
@ -73,6 +90,8 @@ UIInterfaceOrientationMask DefaultUIInterfaceOrientationMask(void)
} }
} }
#pragma mark -
- (void)autoPinViewToBottomOfViewControllerOrKeyboard:(UIView *)view avoidNotch:(BOOL)avoidNotch - (void)autoPinViewToBottomOfViewControllerOrKeyboard:(UIView *)view avoidNotch:(BOOL)avoidNotch
{ {
OWSAssertDebug(view); OWSAssertDebug(view);
@ -185,11 +204,23 @@ UIInterfaceOrientationMask DefaultUIInterfaceOrientationMask(void)
// bar. // bar.
CGFloat offset = -MAX(0, (self.view.height - self.bottomLayoutGuide.length - keyboardEndFrameConverted.origin.y)); CGFloat offset = -MAX(0, (self.view.height - self.bottomLayoutGuide.length - keyboardEndFrameConverted.origin.y));
// There's no need to use: [UIView animateWithDuration:...]. // UIKit by default animates all changes in response to keyboard events.
// Any layout changes made during these notifications are // We want to suppress those animations if the view isn't visible,
// automatically animated. // otherwise presentation animations don't work properly.
self.bottomLayoutConstraint.constant = offset; dispatch_block_t updateLayout = ^{
[self.bottomLayoutView.superview layoutIfNeeded]; // There's no need to use: [UIView animateWithDuration:...].
// Any layout changes made during these notifications are
// automatically animated.
self.bottomLayoutConstraint.constant = offset;
[self.bottomLayoutView.superview layoutIfNeeded];
};
if (self.shouldAnimatedBottomLayout) {
updateLayout();
} else {
[UIView performWithoutAnimation:updateLayout];
}
} }
#pragma mark - Orientation #pragma mark - Orientation

Loading…
Cancel
Save