Skip to content

Commit

Permalink
Added support for a blurred dim view when in edit mode Blackjacx#7
Browse files Browse the repository at this point in the history
  • Loading branch information
narendrakumar.j committed Oct 4, 2023
1 parent 7c9b33f commit b375b32
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Example/Source/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ViewController: UIViewController, SHSearchBarDelegate {
var addressSearchbarTop: SHSearchBar!
var addressSearchbarBottom: SHSearchBar!
var navigationSearchBar: SHSearchBar!
var blurEffectView: UIVisualEffectView?

var viewConstraints: [NSLayoutConstraint]?

Expand Down Expand Up @@ -188,6 +189,14 @@ class ViewController: UIViewController, SHSearchBarDelegate {

viewConstraints = constraints
}

func searchBarDidBeginEditing(_ searchBar: SHSearchBar) {
setEditMode(enabled: true)
}

func searchBarDidEndEditing(_ searchBar: SHSearchBar) {
setEditMode(enabled: false)
}
}

// MARK: - Helper Functions
Expand Down Expand Up @@ -252,3 +261,22 @@ func imageViewWithIcon(_ icon: UIImage, raster: CGFloat) -> UIView {

return container
}

extension ViewController {

func setEditMode(enabled: Bool) {
if enabled {
addBlurView()
} else {
blurEffectView?.removeFromSuperview()
}
}

func addBlurView() {
let blurEffect = UIBlurEffect(style: .light)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView?.frame = view.bounds
blurEffectView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(blurEffectView!)
}
}

0 comments on commit b375b32

Please sign in to comment.