fix initial CaptionView layout glitch

pull/1/head
Michael Kirk 7 years ago
parent e65eeff0fd
commit feb5a0c444

@ -681,7 +681,7 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
// MARK: - View Lifecycle // MARK: - Subviews
lazy var captionView: CaptionView = { lazy var captionView: CaptionView = {
return CaptionView(attachmentItem: attachmentItem) return CaptionView(attachmentItem: attachmentItem)
@ -695,6 +695,8 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
return touchInterceptorView return touchInterceptorView
}() }()
// MARK: - View Lifecycle
override public func loadView() { override public func loadView() {
self.view = UIView() self.view = UIView()
@ -821,6 +823,7 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
// MARK: CaptionView lifts with keyboard // MARK: CaptionView lifts with keyboard
var hasLaidOutCaptionView: Bool = false
var captionViewBottomConstraint: NSLayoutConstraint! var captionViewBottomConstraint: NSLayoutConstraint!
func updateCaptionViewBottomInset() { func updateCaptionViewBottomInset() {
guard let prepDelegate = self.prepDelegate else { guard let prepDelegate = self.prepDelegate else {
@ -828,8 +831,21 @@ public class AttachmentPrepViewController: OWSViewController, PlayerProgressBarD
return return
} }
captionViewBottomConstraint.constant = -prepDelegate.desiredCaptionViewBottomInset let changeBlock = {
captionView.superview?.layoutIfNeeded() self.captionViewBottomConstraint.constant = -prepDelegate.desiredCaptionViewBottomInset
self.captionView.superview?.layoutIfNeeded()
}
// To avoid an animation glitch, we apply this update without animation before initial
// appearance. But after that, we want to apply the constraint change within the existing
// animation context, since we call this while handling a UIKeyboard notification, which
// allows us to slide up the CaptionView in lockstep with the keyboard.
if hasLaidOutCaptionView {
changeBlock()
} else {
hasLaidOutCaptionView = true
UIView.performWithoutAnimation { changeBlock() }
}
} }
// MARK: - Event Handlers // MARK: - Event Handlers

Loading…
Cancel
Save