Skip to content

Commit

Permalink
[CHORE] trying out gradient blur (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
seongmin221 committed Jan 5, 2023
1 parent ba4fd6a commit 42baf10
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
import UIKit

extension UIView {

enum GradientDirection {
case positiveX
case negativeX
case positiveY
case negativeY
}

func setGradient(colorTop: UIColor, colorBottom: UIColor) {
let gradient: CAGradientLayer = CAGradientLayer()
gradient.colors = [colorTop.cgColor, colorBottom.cgColor]
Expand All @@ -18,6 +26,42 @@ extension UIView {
layer.addSublayer(gradient)
}

func setBlurGradient(in direction: GradientDirection, by portion: CGFloat) {
let gradientLayer = CAGradientLayer()
gradientLayer.colors = [
UIColor.backgroundWhite.withAlphaComponent(0).cgColor,
UIColor.backgroundWhite.withAlphaComponent(1).cgColor
]
let viewEffect = UIBlurEffect(style: .light)
let effectView = UIVisualEffectView(effect: viewEffect)
switch direction {
case .positiveX:
effectView.frame = CGRect(x: self.bounds.origin.x, y: self.bounds.origin.y, width: self.bounds.size.width * portion, height: self.bounds.size.height)
effectView.autoresizingMask = [.flexibleWidth]
gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.0)
gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.0)
case .negativeX:
effectView.frame = CGRect(x: self.bounds.origin.x, y: self.bounds.origin.y, width: self.bounds.size.width * portion, height: self.bounds.size.height)
effectView.autoresizingMask = [.flexibleWidth]
gradientLayer.startPoint = CGPoint(x: 1.0, y: 0.0)
gradientLayer.endPoint = CGPoint(x: 0.0, y: 0.0)
case .positiveY:
effectView.frame = CGRect(x: self.bounds.origin.x, y: self.bounds.origin.y, width: self.bounds.size.width, height: self.bounds.size.height * portion)
effectView.autoresizingMask = [.flexibleHeight]
gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.0)
gradientLayer.endPoint = CGPoint(x: 0.0, y: 1.0)
case .negativeY:
effectView.frame = CGRect(x: self.bounds.origin.x, y: self.bounds.origin.y, width: self.bounds.size.width, height: self.bounds.size.height * portion)
effectView.autoresizingMask = [.flexibleHeight]
gradientLayer.startPoint = CGPoint(x: 0.0, y: 1.0)
gradientLayer.endPoint = CGPoint(x: 0.0, y: 0.0)
}
gradientLayer.frame = effectView.frame
effectView.layer.mask = gradientLayer
effectView.isUserInteractionEnabled = false
addSubview(effectView)
}

@discardableResult
func makeShadow(color: UIColor,
opacity: Float,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ final class HomeViewController: BaseViewController {
}
self.flowLayout.count = reflectionKeywordList.count
self.keywordCollectionView.reloadData()
// self.keywordCollectionView.setBlurGradient(in: .negativeY, by: 1)
}
}
}
Expand Down

0 comments on commit 42baf10

Please sign in to comment.