Skip to content

Commit

Permalink
add FilterTintColorControl
Browse files Browse the repository at this point in the history
  • Loading branch information
徐水峰 authored and xu.shuifeng committed Jun 14, 2018
1 parent 8a51f7f commit a9f5fc2
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 116 deletions.
8 changes: 4 additions & 4 deletions MetalFilters.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 */; };
Expand Down Expand Up @@ -121,6 +121,7 @@
A30D742020D0EC1C00824A1A /* MTLocalLaplacianFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTLocalLaplacianFilter.swift; sourceTree = "<group>"; };
A30D742220D0EC2A00824A1A /* MTLocalLaplacianFilter.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = MTLocalLaplacianFilter.metal; sourceTree = "<group>"; };
A32F2BF320D2393E0018C281 /* FilterTintColorPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterTintColorPicker.swift; sourceTree = "<group>"; };
A32F2BFC20D260DC0018C281 /* FilterTintColorControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterTintColorControl.swift; sourceTree = "<group>"; };
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 = "<group>"; };
A36133C520C665A70022F27C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
Expand All @@ -135,7 +136,6 @@
A38FC66520CBEB0E002CA905 /* AlbumPhotoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlbumPhotoViewController.swift; sourceTree = "<group>"; };
A38FC66720CBFBEB002CA905 /* FilterPickerCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterPickerCell.swift; sourceTree = "<group>"; };
A38FC79420CCDA64002CA905 /* MTFilterManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTFilterManager.swift; sourceTree = "<group>"; };
A38FC79620CF40F8002CA905 /* SloppyTouchSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SloppyTouchSlider.swift; sourceTree = "<group>"; };
A38FC79820D1C567002CA905 /* MTTintColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTTintColor.swift; sourceTree = "<group>"; };
A391B28520CE4CB500E6FD67 /* MTSutroFilter.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = MTSutroFilter.metal; sourceTree = "<group>"; };
A391B28620CE4CB500E6FD67 /* MTReyesFilter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MTReyesFilter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
4 changes: 2 additions & 2 deletions MetalFilters/Supports/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="u9O-hJ-4li" userLabel="Filters View">
<rect key="frame" x="0.0" y="407" width="375" height="216"/>
<rect key="frame" x="0.0" y="395" width="375" height="228"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Lix-sF-hlR" userLabel="Toobar View">
Expand Down Expand Up @@ -140,7 +140,7 @@
<constraint firstItem="V4X-Bw-skj" firstAttribute="top" secondItem="oJJ-HM-wNQ" secondAttribute="top" id="5Na-Gv-IBj"/>
<constraint firstItem="oJJ-HM-wNQ" firstAttribute="bottom" secondItem="Lix-sF-hlR" secondAttribute="bottom" id="6PB-Hg-iQW"/>
<constraint firstItem="oJJ-HM-wNQ" firstAttribute="trailing" secondItem="Lix-sF-hlR" secondAttribute="trailing" id="B7m-7w-EFM"/>
<constraint firstItem="u9O-hJ-4li" firstAttribute="top" secondItem="V4X-Bw-skj" secondAttribute="bottom" constant="12" id="Fhg-Ga-rAm"/>
<constraint firstItem="u9O-hJ-4li" firstAttribute="top" secondItem="V4X-Bw-skj" secondAttribute="bottom" id="Fhg-Ga-rAm"/>
<constraint firstItem="oJJ-HM-wNQ" firstAttribute="trailing" secondItem="u9O-hJ-4li" secondAttribute="trailing" id="Kd5-rD-WY2"/>
<constraint firstItem="u9O-hJ-4li" firstAttribute="leading" secondItem="oJJ-HM-wNQ" secondAttribute="leading" id="N8v-HE-gP5"/>
<constraint firstItem="Lix-sF-hlR" firstAttribute="top" secondItem="u9O-hJ-4li" secondAttribute="bottom" id="fE7-f0-7Wd"/>
Expand Down
34 changes: 24 additions & 10 deletions MetalFilters/ViewControllers/PhotoEditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}

Expand Down
90 changes: 90 additions & 0 deletions MetalFilters/Views/FilterTintColorControl.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
}
100 changes: 0 additions & 100 deletions MetalFilters/Views/SloppyTouchSlider.swift

This file was deleted.

0 comments on commit a9f5fc2

Please sign in to comment.