[iphonex] [ios] Updated constraints animations.

This commit is contained in:
Ilya Grechuhin 2017-12-28 12:34:44 +03:00 committed by Roman Kuznetsov
parent f462dc0836
commit b2bcdd2889
5 changed files with 57 additions and 61 deletions

View file

@ -59,14 +59,12 @@ final class BaseRoutePreviewStatus: SolidTouchView {
}
DispatchQueue.main.async {
guard let sv = self.superview else { return }
sv.setNeedsLayout()
self.hiddenConstraint.isActive = !self.isVisible
UIView.animate(withDuration: kDefaultAnimationDuration,
animations: { sv.layoutIfNeeded() },
completion: { _ in
if !self.isVisible {
self.removeFromSuperview()
}
sv.animateConstraints(animations: {
self.hiddenConstraint.isActive = !self.isVisible
}, completion: {
if !self.isVisible {
self.removeFromSuperview()
}
})
}
},
@ -101,18 +99,20 @@ final class BaseRoutePreviewStatus: SolidTouchView {
let visibleConstraint = bottomAnchor.constraint(equalTo: bAnchor)
visibleConstraint.priority = UILayoutPriority.defaultLow
visibleConstraint.isActive = true
ownerView.layoutIfNeeded()
}
private func updateHeight() {
DispatchQueue.main.async {
self.setNeedsLayout()
self.errorBoxBottom.isActive = !self.errorBox.isHidden
self.resultsBoxBottom.isActive = !self.resultsBox.isHidden
self.heightBoxBottom.isActive = !self.heightBox.isHidden
self.heightBoxBottomManageRouteBoxTop.isActive = !self.heightBox.isHidden
self.taxiBoxBottom.isActive = !self.taxiBox.isHidden
self.manageRouteBoxBottom.isActive = !self.manageRouteBox.isHidden
UIView.animate(withDuration: kDefaultAnimationDuration) { self.layoutIfNeeded() }
self.animateConstraints(animations: {
self.errorBoxBottom.isActive = !self.errorBox.isHidden
self.resultsBoxBottom.isActive = !self.resultsBox.isHidden
self.heightBoxBottom.isActive = !self.heightBox.isHidden
self.heightBoxBottomManageRouteBoxTop.isActive = !self.heightBox.isHidden
self.taxiBoxBottom.isActive = !self.taxiBox.isHidden
self.manageRouteBoxBottom.isActive = !self.manageRouteBox.isHidden
})
}
}

View file

@ -18,14 +18,12 @@ final class TransportRoutePreviewStatus: SolidTouchView {
}
DispatchQueue.main.async {
guard let sv = self.superview else { return }
sv.setNeedsLayout()
self.hiddenConstraint.isActive = !self.isVisible
UIView.animate(withDuration: kDefaultAnimationDuration,
animations: { sv.layoutIfNeeded() },
completion: { _ in
if !self.isVisible {
self.removeFromSuperview()
}
sv.animateConstraints(animations: {
self.hiddenConstraint.isActive = !self.isVisible
}, completion: {
if !self.isVisible {
self.removeFromSuperview()
}
})
}
},
@ -80,9 +78,9 @@ final class TransportRoutePreviewStatus: SolidTouchView {
private func updateHeight() {
guard stepsCollectionViewHeight.constant != stepsCollectionView.contentSize.height else { return }
DispatchQueue.main.async {
self.setNeedsLayout()
self.stepsCollectionViewHeight.constant = self.stepsCollectionView.contentSize.height
UIView.animate(withDuration: kDefaultAnimationDuration) { self.layoutIfNeeded() }
self.animateConstraints(animations: {
self.stepsCollectionViewHeight.constant = self.stepsCollectionView.contentSize.height
})
}
}

View file

@ -76,12 +76,12 @@ final class AdBanner: UITableViewCell {
}
guard state != oldValue else { return }
let config = state.config()
adTitleLabel.numberOfLines = config.numberOfTitleLines
adBodyLabel.numberOfLines = config.numberOfBodyLines
detailedModeConstraints.forEach { $0.priority = config.priority }
setNeedsLayout()
UIView.animate(withDuration: kDefaultAnimationDuration) { self.layoutIfNeeded() }
refreshBannerIfNeeded()
animateConstraints(animations: {
self.adTitleLabel.numberOfLines = config.numberOfTitleLines
self.adBodyLabel.numberOfLines = config.numberOfBodyLines
self.detailedModeConstraints.forEach { $0.priority = config.priority }
self.refreshBannerIfNeeded()
})
}
}

View file

@ -36,14 +36,11 @@ final class PPHotelDescriptionCell: MWMTableViewCell {
}
@IBAction private func tap() {
compactModeConstraints.forEach { $0.priority = UILayoutPriority.defaultLow }
hideButton()
setNeedsLayout()
UIView.animate(withDuration: kDefaultAnimationDuration, animations: { [weak self] in
guard let s = self else { return }
s.layoutIfNeeded()
s.updateDelegate?.cellUpdated()
animateConstraints(animations: {
self.compactModeConstraints.forEach { $0.priority = UILayoutPriority.defaultLow }
self.hideButton()
}, completion: {
self.updateDelegate?.cellUpdated()
})
}
}

View file

@ -82,32 +82,33 @@ final class CianElement: UICollectionViewCell {
var state: State! {
didSet {
setupAppearance()
setNeedsLayout()
contentViews.forEach { $0.isHidden = false }
let visibleView: UIView
var pendingSpinnerViewAlpha: CGFloat = 1
let pendingSpinnerViewAlpha: CGFloat
switch state! {
case .pending:
visibleView = pendingView
configPending()
case let .offer(model, _):
visibleView = offerView
configOffer(model: model)
pendingSpinnerViewAlpha = 1
visibleView = self.pendingView
case .offer:
pendingSpinnerViewAlpha = 1
visibleView = self.offerView
case .error:
pendingSpinnerViewAlpha = 0
visibleView = pendingView
configError()
visibleView = self.pendingView
}
UIView.animate(withDuration: kDefaultAnimationDuration,
animations: {
self.pendingSpinnerView.alpha = pendingSpinnerViewAlpha
self.contentViews.forEach { $0.alpha = 0 }
visibleView.alpha = 1
self.layoutIfNeeded()
},
completion: { _ in
self.contentViews.forEach { $0.isHidden = true }
visibleView.isHidden = false
animateConstraints(animations: {
self.contentViews.forEach { $0.isHidden = false }
switch self.state! {
case .pending: self.configPending()
case let .offer(model, _): self.configOffer(model: model)
case .error: self.configError()
}
self.pendingSpinnerView.alpha = pendingSpinnerViewAlpha
self.contentViews.forEach { $0.alpha = 0 }
visibleView.alpha = 1
}, completion: {
self.contentViews.forEach { $0.isHidden = true }
visibleView.isHidden = false
})
}
}