Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Blurred background image

  • Loading branch information
Tim Palade authored and mahmoud-adam85 committed May 11, 2018
1 parent e08ae96 commit 63c9102d9f5ca55b8c000d8a94437cd5e61e1ce1
Showing with 41 additions and 9 deletions.
  1. +16 −8 Cliqz/Extensions/ImageExtension.swift
  2. +25 −1 Cliqz/HomePanel/CliqzHomePanelViewController.swift
@@ -9,26 +9,34 @@
import UIKit

extension UIImage {
static func cliqzBackgroundImage() -> UIImage? {
static func cliqzBackgroundImage(blurred: Bool = false) -> UIImage? {

let (device, orientation) = UIDevice.current.getDeviceAndOrientation()

let image: UIImage?
switch device {
case .iPhone:
if orientation == .portrait {
return UIImage(named: "iPhonePortrait")
image = UIImage(named: "iPhonePortrait")
}
else {
image = UIImage(named: "iPhoneLandscape")
}
return UIImage(named: "iPhoneLandscape")
case .iPhoneX:
if orientation == .portrait {
return UIImage(named: "iPhoneXPortrait")
image = UIImage(named: "iPhoneXPortrait")
}
else {
image = UIImage(named: "iPhoneXLandscape")
}
return UIImage(named: "iPhoneXLandscape")
case .iPad:
if orientation == .portrait {
return UIImage(named: "iPadPortrait")
image = UIImage(named: "iPadPortrait")
}
else {
image = UIImage(named: "iPadLandscape")
}
return UIImage(named: "iPadLandscape")
}

return blurred ? image?.applyBlur(withRadius: 5, blurType: BOXFILTER, tintColor: UIColor.clear, saturationDeltaFactor: 1.0, maskImage: nil) : image
}
}
@@ -52,6 +52,14 @@ class CliqzHomePanelViewController: UIViewController, UITextFieldDelegate {
fileprivate let segmentedControl: UISegmentedControl
fileprivate let controllerContainerView: UIView = UIView()

enum IndexType {
case blurred
case notBlurred
case notSet
}

fileprivate var currentIndexType: IndexType = .notSet

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {

self.panels = CliqzHomePanels().enabledPanels
@@ -113,7 +121,22 @@ class CliqzHomePanelViewController: UIViewController, UITextFieldDelegate {
}

func setBackgroundImage() {
backgroundView.image = UIImage.cliqzBackgroundImage()//?.applyBlur(withRadius: 5, blurType: BOXFILTER, tintColor: UIColor.black.withAlphaComponent(0.1), saturationDeltaFactor: 1.8, maskImage: nil)

func index2type(_ index: Int) -> IndexType {
return index < 1 ? .notBlurred : .blurred
}

let indexType = index2type(segmentedControl.selectedSegmentIndex)

guard currentIndexType != indexType else { return }
currentIndexType = indexType

if segmentedControl.selectedSegmentIndex < 1 {
backgroundView.image = UIImage.cliqzBackgroundImage()
}
else {
backgroundView.image = UIImage.cliqzBackgroundImage(blurred: true)
}
}

func dismissKeyboard(_ sender: Any? = nil) {
@@ -125,6 +148,7 @@ extension CliqzHomePanelViewController {

@objc func segmentedControlValueChanged(control: UISegmentedControl) {
self.dismissKeyboard()
setBackgroundImage()
selectedPanel = HomePanelType(rawValue: control.selectedSegmentIndex) //control.selectedSegmentIndex must be between 0 and 3
}

0 comments on commit 63c9102

Please sign in to comment.