From a9f5fc22e13e95b82d57c7f650025efe6aa4964d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B0=B4=E5=B3=B0?= Date: Thu, 14 Jun 2018 18:54:04 +0800 Subject: [PATCH] add FilterTintColorControl --- MetalFilters.xcodeproj/project.pbxproj | 8 +- .../Supports/Base.lproj/Main.storyboard | 4 +- .../PhotoEditorViewController.swift | 34 ++++-- .../Views/FilterTintColorControl.swift | 90 ++++++++++++++++ MetalFilters/Views/SloppyTouchSlider.swift | 100 ------------------ 5 files changed, 120 insertions(+), 116 deletions(-) create mode 100644 MetalFilters/Views/FilterTintColorControl.swift delete mode 100644 MetalFilters/Views/SloppyTouchSlider.swift diff --git a/MetalFilters.xcodeproj/project.pbxproj b/MetalFilters.xcodeproj/project.pbxproj index ec6a446..836b042 100644 --- a/MetalFilters.xcodeproj/project.pbxproj +++ b/MetalFilters.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ A30D742120D0EC1C00824A1A /* MTLocalLaplacianFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A30D742020D0EC1C00824A1A /* MTLocalLaplacianFilter.swift */; }; A30D742320D0EC2A00824A1A /* MTLocalLaplacianFilter.metal in Sources */ = {isa = PBXBuildFile; fileRef = A30D742220D0EC2A00824A1A /* MTLocalLaplacianFilter.metal */; }; A32F2BF420D2393E0018C281 /* FilterTintColorPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = A32F2BF320D2393E0018C281 /* FilterTintColorPicker.swift */; }; + A32F2BFD20D260DC0018C281 /* FilterTintColorControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = A32F2BFC20D260DC0018C281 /* FilterTintColorControl.swift */; }; A36133C120C665A70022F27C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A36133C020C665A70022F27C /* AppDelegate.swift */; }; A36133C620C665A70022F27C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A36133C420C665A70022F27C /* Main.storyboard */; }; A36133C820C665A70022F27C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A36133C720C665A70022F27C /* Assets.xcassets */; }; @@ -23,7 +24,6 @@ A38FC66620CBEB0E002CA905 /* AlbumPhotoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC66520CBEB0E002CA905 /* AlbumPhotoViewController.swift */; }; A38FC66820CBFBEB002CA905 /* FilterPickerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC66720CBFBEB002CA905 /* FilterPickerCell.swift */; }; A38FC79520CCDA64002CA905 /* MTFilterManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC79420CCDA64002CA905 /* MTFilterManager.swift */; }; - A38FC79720CF40F8002CA905 /* SloppyTouchSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC79620CF40F8002CA905 /* SloppyTouchSlider.swift */; }; A38FC79920D1C568002CA905 /* MTTintColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38FC79820D1C567002CA905 /* MTTintColor.swift */; }; A391B2D720CE4CCA00E6FD67 /* MTSutroFilter.metal in Sources */ = {isa = PBXBuildFile; fileRef = A391B28520CE4CB500E6FD67 /* MTSutroFilter.metal */; }; A391B2D820CE4CCA00E6FD67 /* MTReyesFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A391B28620CE4CB500E6FD67 /* MTReyesFilter.swift */; }; @@ -121,6 +121,7 @@ A30D742020D0EC1C00824A1A /* MTLocalLaplacianFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTLocalLaplacianFilter.swift; sourceTree = ""; }; A30D742220D0EC2A00824A1A /* MTLocalLaplacianFilter.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = MTLocalLaplacianFilter.metal; sourceTree = ""; }; A32F2BF320D2393E0018C281 /* FilterTintColorPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterTintColorPicker.swift; sourceTree = ""; }; + A32F2BFC20D260DC0018C281 /* FilterTintColorControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterTintColorControl.swift; sourceTree = ""; }; A36133BD20C665A70022F27C /* MetalFilters.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MetalFilters.app; sourceTree = BUILT_PRODUCTS_DIR; }; A36133C020C665A70022F27C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; A36133C520C665A70022F27C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -135,7 +136,6 @@ A38FC66520CBEB0E002CA905 /* AlbumPhotoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlbumPhotoViewController.swift; sourceTree = ""; }; A38FC66720CBFBEB002CA905 /* FilterPickerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterPickerCell.swift; sourceTree = ""; }; A38FC79420CCDA64002CA905 /* MTFilterManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTFilterManager.swift; sourceTree = ""; }; - A38FC79620CF40F8002CA905 /* SloppyTouchSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SloppyTouchSlider.swift; sourceTree = ""; }; A38FC79820D1C567002CA905 /* MTTintColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTTintColor.swift; sourceTree = ""; }; A391B28520CE4CB500E6FD67 /* MTSutroFilter.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = MTSutroFilter.metal; sourceTree = ""; }; A391B28620CE4CB500E6FD67 /* MTReyesFilter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MTReyesFilter.swift; sourceTree = ""; }; @@ -422,10 +422,10 @@ A38FC66320CBEAA5002CA905 /* AlbumPhotoCell.swift */, A38FC66720CBFBEB002CA905 /* FilterPickerCell.swift */, A3A068DA20CF67F300A2DF76 /* ToolPickerCell.swift */, - A38FC79620CF40F8002CA905 /* SloppyTouchSlider.swift */, A3A068DE20CFA92F00A2DF76 /* FilterControlView.swift */, A3A068E420CFCE3800A2DF76 /* HorizontalSliderView.swift */, A32F2BF320D2393E0018C281 /* FilterTintColorPicker.swift */, + A32F2BFC20D260DC0018C281 /* FilterTintColorControl.swift */, ); path = Views; sourceTree = ""; @@ -559,6 +559,7 @@ A391B30D20CE4CCA00E6FD67 /* MTAdenFilter.metal in Sources */, A391B32020CE4CCA00E6FD67 /* MTWaldenFilter.swift in Sources */, A391B2F120CE4CCA00E6FD67 /* MTCharmesVideoFilter.metal in Sources */, + A32F2BFD20D260DC0018C281 /* FilterTintColorControl.swift in Sources */, A391B32420CE4CCA00E6FD67 /* MTInkwellFilter.metal in Sources */, A391B2D920CE4CCA00E6FD67 /* MTVesperVideoFilter.swift in Sources */, A391B2DC20CE4CCA00E6FD67 /* MTXpro2Filter.swift in Sources */, @@ -635,7 +636,6 @@ A391B31B20CE4CCA00E6FD67 /* MTPerpetuaFilter.metal in Sources */, A391B30220CE4CCA00E6FD67 /* MTLudwigFilter.metal in Sources */, A391B2F820CE4CCA00E6FD67 /* MTRiseFilter.metal in Sources */, - A38FC79720CF40F8002CA905 /* SloppyTouchSlider.swift in Sources */, A391B32620CE4CCA00E6FD67 /* MTBrooklynVideoFilter.swift in Sources */, A391B30820CE4CCA00E6FD67 /* MTBrannanFilter.swift in Sources */, A391B2E420CE4CCA00E6FD67 /* MTMavenVideoFilter.swift in Sources */, diff --git a/MetalFilters/Supports/Base.lproj/Main.storyboard b/MetalFilters/Supports/Base.lproj/Main.storyboard index 96b5e49..1a9c317 100644 --- a/MetalFilters/Supports/Base.lproj/Main.storyboard +++ b/MetalFilters/Supports/Base.lproj/Main.storyboard @@ -83,7 +83,7 @@ - + @@ -140,7 +140,7 @@ - + diff --git a/MetalFilters/ViewControllers/PhotoEditorViewController.swift b/MetalFilters/ViewControllers/PhotoEditorViewController.swift index ff8e29b..7242db3 100644 --- a/MetalFilters/ViewControllers/PhotoEditorViewController.swift +++ b/MetalFilters/ViewControllers/PhotoEditorViewController.swift @@ -239,17 +239,31 @@ class PhotoEditorViewController: UIViewController { let width = self.filtersView.bounds.width let height = self.filtersView.bounds.height + 44 let frame = CGRect(x: 0, y: view.bounds.height - height + 44, width: width, height: height) - let value = valueForFilterControlView(with: tool) - let controlView = FilterControlView(frame: frame, filterTool: tool, value: value) - controlView.delegate = self - filterControlView = controlView - UIView.animate(withDuration: 0.2, animations: { - self.view.addSubview(controlView) - controlView.setPosition(offScreen: false) - }) { finish in - self.title = tool.title - self.clearNavigationButton() + if tool.type == .color { + let colorControlView = FilterTintColorControl(frame: frame) + UIView.animate(withDuration: 0.2, animations: { + self.view.addSubview(colorControlView) + colorControlView.setPosition(offScreen: false) + }) { finish in + self.title = tool.title + self.clearNavigationButton() + } + } else if tool.type == .adjust { + + } else { + let value = valueForFilterControlView(with: tool) + let controlView = FilterControlView(frame: frame, filterTool: tool, value: value) + controlView.delegate = self + filterControlView = controlView + + UIView.animate(withDuration: 0.2, animations: { + self.view.addSubview(controlView) + controlView.setPosition(offScreen: false) + }) { finish in + self.title = tool.title + self.clearNavigationButton() + } } } diff --git a/MetalFilters/Views/FilterTintColorControl.swift b/MetalFilters/Views/FilterTintColorControl.swift new file mode 100644 index 0000000..f577fe3 --- /dev/null +++ b/MetalFilters/Views/FilterTintColorControl.swift @@ -0,0 +1,90 @@ +// +// FilterTintColorControl.swift +// MetalFilters +// +// Created by xu.shuifeng on 2018/6/14. +// Copyright © 2018 shuifeng.me. All rights reserved. +// + +import UIKit + +class FilterTintColorControl: UIView, UITabBarDelegate { + + private let tabBar: UITabBar + + private let shadowTabItem: UITabBarItem + + private let highlightTabItem: UITabBarItem + + private let colorPicker: FilterTintColorPicker + + private let slider: HorizontalSliderView + + let titleNormalColor = UIColor(red: 0.6, green: 0.6, blue: 0.6, alpha: 1) + let titleSelectedColor = UIColor(red: 0.15, green: 0.15, blue: 0.15, alpha: 1) + + override init(frame: CGRect) { + + tabBar = UITabBar(frame: CGRect(x: 0, y: 0, width: frame.width, height: 30)) + UITabBar.appearance().clipsToBounds = true + UITabBar.appearance().layer.borderWidth = 1 + tabBar.backgroundColor = UIColor.white + tabBar.itemPositioning = .fill + tabBar.isTranslucent = false + tabBar.shadowImage = nil + + shadowTabItem = UITabBarItem(title: "Shadows", image: nil, selectedImage: nil) + shadowTabItem.titlePositionAdjustment = .zero + shadowTabItem.setTitleTextAttributes([.font: UIFont.systemFont(ofSize: 13, weight: .semibold), + .foregroundColor: titleNormalColor], for: .normal) + shadowTabItem.setTitleTextAttributes([.font: UIFont.systemFont(ofSize: 13, weight: .semibold), + .foregroundColor: titleSelectedColor], for: .selected) + + highlightTabItem = UITabBarItem(title: "Highlights", image: nil, selectedImage: nil) + highlightTabItem.setTitleTextAttributes([.font: UIFont.systemFont(ofSize: 13, weight: .semibold), + .foregroundColor: titleNormalColor], for: .normal) + highlightTabItem.setTitleTextAttributes([.font: UIFont.systemFont(ofSize: 13, weight: .semibold), + .foregroundColor: titleSelectedColor], for: .selected) + + + + colorPicker = FilterTintColorPicker(frame: .zero) + slider = HorizontalSliderView(frame: .zero) + + super.init(frame: frame) + + backgroundColor = .white + + addSubview(tabBar) + addSubview(colorPicker) +// addSubview(slider) + + tabBar.items = [shadowTabItem, highlightTabItem] + tabBar.selectedItem = shadowTabItem + tabBar.delegate = self + } + + override func layoutSubviews() { + super.layoutSubviews() + + tabBar.frame = CGRect(x: 0, y: 0, width: frame.width, height: 30) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) { + + } + + func setPosition(offScreen isOffScreen: Bool) { + if isOffScreen { + frame.origin = CGPoint(x: frame.origin.x, y: frame.origin.y + 44) + alpha = 0 + } else { + frame.origin = CGPoint(x: frame.origin.x, y: frame.origin.y - 44) + alpha = 1 + } + } +} diff --git a/MetalFilters/Views/SloppyTouchSlider.swift b/MetalFilters/Views/SloppyTouchSlider.swift deleted file mode 100644 index 8d447ae..0000000 --- a/MetalFilters/Views/SloppyTouchSlider.swift +++ /dev/null @@ -1,100 +0,0 @@ -// -// SloppyTouchSlider.swift -// MetalFilters -// -// Created by xushuifeng on 2018/6/12. -// Copyright © 2018 shuifeng.me. All rights reserved. -// - -import UIKit - -public struct SloppyTouchSliderConfiguration { - let thumbViewShadowOpacity: CGFloat - let thumbViewShadowOffset: CGSize - let thumbViewShadowRadius: CGFloat - - let trackShadowOpacity: CGFloat - let trackShadowOffset: CGSize - let trackShadowRadius: CGFloat - let trackHeight: CGFloat - let defaultTrackColor: UIColor -} - -public class SloppyTouchSlider: UIControl { - - var trackView: UIView - - var highlightedTrackView: UIView - - var centerView: UIImageView - - var feedbackGenerator: UISelectionFeedbackGenerator - - public var value: Double = 0 - - private var tapGesture: UITapGestureRecognizer! - private var panGesture: UIPanGestureRecognizer! - private var sliderPosition: Double! - private var panValueOrigin: Double! - private var panOrigin: CGPoint = .zero - private var config: SloppyTouchSliderConfiguration! - - override public init(frame: CGRect) { - trackView = UIView() - highlightedTrackView = UIView() - centerView = UIImageView() - feedbackGenerator = UISelectionFeedbackGenerator() - super.init(frame: frame) - } - - public init(frame: CGRect, useTriangularTrack: Bool, configuration: SloppyTouchSliderConfiguration) { - trackView = UIView() - highlightedTrackView = UIView() - centerView = UIImageView() - feedbackGenerator = UISelectionFeedbackGenerator() - config = configuration - super.init(frame: frame) - } - - private func commonInit() { - - } - - required public init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override public func layoutSubviews() { - super.layoutSubviews() - } - - func trackRectForBounds() -> CGRect { - let bounds = self.bounds - let height = config.trackHeight - return .zero - } - - override public func touchesBegan(_ touches: Set, with event: UIEvent?) { - - } - - override public func touchesMoved(_ touches: Set, with event: UIEvent?) { - - } - - override public func touchesEnded(_ touches: Set, with event: UIEvent?) { - - } - - override public func touchesCancelled(_ touches: Set, with event: UIEvent?) { - - } - - override public func point(inside point: CGPoint, with event: UIEvent?) -> Bool { - return true - } -} - -extension SloppyTouchSlider: UIGestureRecognizerDelegate { - -}