fix gradient background

This commit is contained in:
ryanzhao 2022-09-28 14:26:07 +10:00
parent 47d41ea64d
commit bd1e1b266b
3 changed files with 12 additions and 5 deletions

View File

@ -46,12 +46,12 @@ final class FakeChatView : UIView {
stackView.axis = .vertical
stackView.spacing = spacing
stackView.alignment = .fill
stackView.set(.width, to: UIScreen.main.bounds.width)
let vInset = Values.smallSpacing
stackView.layoutMargins = UIEdgeInsets(top: vInset, leading: Values.veryLargeSpacing, bottom: vInset, trailing: Values.veryLargeSpacing)
stackView.isLayoutMarginsRelativeArrangement = true
scrollView.addSubview(stackView)
stackView.pin(to: scrollView)
stackView.set(.width, to: .width, of: scrollView)
addSubview(scrollView)
scrollView.pin(to: self)
let height = chatBubbles.reduce(0) { $0 + $1.systemLayoutSizeFitting(UIView.layoutFittingExpandedSize).height } + CGFloat(chatBubbles.count - 1) * spacing + 2 * vInset

View File

@ -28,6 +28,13 @@ class BaseVC : UIViewController {
NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActive(_:)), name: .OWSApplicationDidBecomeActive, object: nil)
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
if hasGradient {
let frame = CGRect(x: 0, y: 0, width: size.width, height: size.height)
setUpGradientBackground(frame: frame)
}
}
internal func ensureWindowBackground() {
let appMode = AppModeManager.shared.currentAppMode
switch appMode {
@ -38,11 +45,11 @@ class BaseVC : UIViewController {
}
}
internal func setUpGradientBackground() {
internal func setUpGradientBackground(frame: CGRect = UIScreen.main.bounds) {
hasGradient = true
view.backgroundColor = .clear
let gradient = Gradients.defaultBackground
view.setGradient(gradient)
view.setGradient(gradient, frame: frame)
}
internal func setUpNavBarStyle() {

View File

@ -16,9 +16,9 @@ public final class Gradient : NSObject {
@objc public extension UIView {
@objc func setGradient(_ gradient: Gradient) {
@objc func setGradient(_ gradient: Gradient, frame: CGRect = UIScreen.main.bounds) {
let layer = CAGradientLayer()
layer.frame = UIScreen.main.bounds
layer.frame = frame
layer.colors = [ gradient.start.cgColor, gradient.end.cgColor ]
if let existingSublayer = self.layer.sublayers?[0], existingSublayer is CAGradientLayer {
self.layer.replaceSublayer(existingSublayer, with: layer)