From 952e31098291b6f4675886d1951374d5004d0e9e Mon Sep 17 00:00:00 2001 From: Chris Li Date: Wed, 29 Jun 2016 16:36:04 -0400 Subject: [PATCH] finished! finish recent search bar shadow & background transition when hSizeClass change --- Kiwix-iOS/Info.plist | 2 +- Kiwix-iOS/Storyboard/Search.storyboard | 12 +++++--- Kiwix-iOS/View/ShadowView.swift | 39 ++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 8b3f8477..d525c818 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -36,7 +36,7 @@ CFBundleSignature ???? CFBundleVersion - 849 + 878 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOS/Storyboard/Search.storyboard b/Kiwix-iOS/Storyboard/Search.storyboard index 2e76f997..0d276a78 100644 --- a/Kiwix-iOS/Storyboard/Search.storyboard +++ b/Kiwix-iOS/Storyboard/Search.storyboard @@ -75,7 +75,9 @@ - + + + @@ -112,7 +114,9 @@ - + + + @@ -938,7 +942,7 @@ - + @@ -975,7 +979,7 @@ - + diff --git a/Kiwix-iOS/View/ShadowView.swift b/Kiwix-iOS/View/ShadowView.swift index 6f98de05..278821de 100644 --- a/Kiwix-iOS/View/ShadowView.swift +++ b/Kiwix-iOS/View/ShadowView.swift @@ -9,17 +9,50 @@ import UIKit class DropShadowView: UIView { + var bottomBorder: CALayer? override func drawRect(rect: CGRect) { + switch traitCollection.horizontalSizeClass { + case .Regular: + layer.shadowRadius = 0.0 + layer.shadowOpacity = 0.0 + layer.backgroundColor = UIColor.whiteColor().CGColor + + let border: CALayer = { + if let border = bottomBorder { + return border + } else { + let border = CALayer() + bottomBorder = border + border.backgroundColor = UIColor.lightGrayColor().colorWithAlphaComponent(0.75).CGColor + border.frame = CGRectMake(0, rect.height - 0.5, rect.width, 0.5) + return border + } + }() + layer.addSublayer(border) + case .Compact: + layer.shadowRadius = 2.0 + layer.shadowOpacity = 0.5 + layer.backgroundColor = UIColor(red: 240/255, green: 240/255, blue: 240/255, alpha: 1.0).CGColor + if let border = bottomBorder {border.removeFromSuperlayer()} + default: + break + } + } + + override func awakeFromNib() { layer.masksToBounds = false layer.shadowOffset = CGSizeMake(0, 0) - layer.shadowRadius = 2.0 - layer.shadowOpacity = 0.5 } override func layoutSubviews() { super.layoutSubviews() layer.shadowPath = UIBezierPath(rect: bounds).CGPath } + + override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) { + guard previousTraitCollection != traitCollection else {return} + setNeedsDisplay() + } } class SearchHRegularDropShadowView: UIView { @@ -28,7 +61,7 @@ class SearchHRegularDropShadowView: UIView { layer.cornerRadius = 10.0 layer.shadowOffset = CGSizeMake(0, 0) layer.shadowRadius = 50.0 - layer.shadowOpacity = 0.1 + layer.shadowOpacity = 0.2 } override func layoutSubviews() {