Skip to content

Commit

Permalink
normal模式也转换成实时滤镜,提高切换的效率,并且重构了切换滤镜的UI
Browse files Browse the repository at this point in the history
  • Loading branch information
chunzhiying committed Oct 18, 2015
1 parent 6c9eaf7 commit 49df353
Show file tree
Hide file tree
Showing 11 changed files with 435 additions and 66 deletions.
8 changes: 8 additions & 0 deletions MeiPaiDemo/MeiPaiDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
9869A7261BBFC7AC002496A1 /* LoadingBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 9869A7241BBFC7AC002496A1 /* LoadingBox.m */; settings = {ASSET_TAGS = (); }; };
9869A7271BBFC7AC002496A1 /* LoadingBox.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9869A7251BBFC7AC002496A1 /* LoadingBox.xib */; settings = {ASSET_TAGS = (); }; };
9869A72D1BBFCCC5002496A1 /* RecordModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9869A72C1BBFCCC5002496A1 /* RecordModel.swift */; settings = {ASSET_TAGS = (); }; };
988118AD1BD329C000ED168D /* Common.swift in Sources */ = {isa = PBXBuildFile; fileRef = 988118AC1BD329C000ED168D /* Common.swift */; settings = {ASSET_TAGS = (); }; };
98A465591BCE0693005244C5 /* RealTimeFilterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A465581BCE0693005244C5 /* RealTimeFilterView.swift */; settings = {ASSET_TAGS = (); }; };
98B23E6F1BC7B7C000D4189F /* PhotosModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B23E6E1BC7B7C000D4189F /* PhotosModel.swift */; settings = {ASSET_TAGS = (); }; };
98B23E711BC7D32300D4189F /* VideoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B23E701BC7D32300D4189F /* VideoCell.swift */; settings = {ASSET_TAGS = (); }; };
98C473711BD2317F00AC084D /* FilterScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98C473701BD2317F00AC084D /* FilterScrollView.swift */; settings = {ASSET_TAGS = (); }; };
98E88B671BBA878D00D4D18D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98E88B661BBA878D00D4D18D /* AppDelegate.swift */; };
98E88B6C1BBA878D00D4D18D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 98E88B6A1BBA878D00D4D18D /* Main.storyboard */; };
98E88B6E1BBA878D00D4D18D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 98E88B6D1BBA878D00D4D18D /* Assets.xcassets */; };
Expand All @@ -36,9 +38,11 @@
9869A7241BBFC7AC002496A1 /* LoadingBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LoadingBox.m; sourceTree = "<group>"; };
9869A7251BBFC7AC002496A1 /* LoadingBox.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LoadingBox.xib; sourceTree = "<group>"; };
9869A72C1BBFCCC5002496A1 /* RecordModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordModel.swift; sourceTree = "<group>"; };
988118AC1BD329C000ED168D /* Common.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Common.swift; sourceTree = "<group>"; };
98A465581BCE0693005244C5 /* RealTimeFilterView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealTimeFilterView.swift; sourceTree = "<group>"; };
98B23E6E1BC7B7C000D4189F /* PhotosModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosModel.swift; sourceTree = "<group>"; };
98B23E701BC7D32300D4189F /* VideoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoCell.swift; sourceTree = "<group>"; };
98C473701BD2317F00AC084D /* FilterScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterScrollView.swift; sourceTree = "<group>"; };
98E88B631BBA878D00D4D18D /* MeiPaiDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MeiPaiDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
98E88B661BBA878D00D4D18D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
98E88B6B1BBA878D00D4D18D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -67,6 +71,7 @@
9838E8DE1BBD34B900698408 /* Common */ = {
isa = PBXGroup;
children = (
988118AC1BD329C000ED168D /* Common.swift */,
9869A7221BBFC7AC002496A1 /* LoadingBox */,
9838E8E01BBD3FFB00698408 /* HWWeakTimer */,
);
Expand Down Expand Up @@ -113,6 +118,7 @@
isa = PBXGroup;
children = (
9838E8DC1BBD2DBB00698408 /* RecordVideoView.swift */,
98C473701BD2317F00AC084D /* FilterScrollView.swift */,
98A465581BCE0693005244C5 /* RealTimeFilterView.swift */,
);
name = MeiPai;
Expand Down Expand Up @@ -300,11 +306,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
988118AD1BD329C000ED168D /* Common.swift in Sources */,
98E88B671BBA878D00D4D18D /* AppDelegate.swift in Sources */,
98E88B7F1BBA8E0A00D4D18D /* MPMainTabBarController.swift in Sources */,
9869A72D1BBFCCC5002496A1 /* RecordModel.swift in Sources */,
98E88B881BBA8F9400D4D18D /* ProfileViewController.swift in Sources */,
98F970A21BC9F8A00033E231 /* PlayViewController.swift in Sources */,
98C473711BD2317F00AC084D /* FilterScrollView.swift in Sources */,
98A465591BCE0693005244C5 /* RealTimeFilterView.swift in Sources */,
98E88B841BBA8F3C00D4D18D /* HomeViewController.swift in Sources */,
98E88B861BBA8F8100D4D18D /* RecordViewController.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,102 @@
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "MeiPaiDemo/RecordVideoView.swift"
timestampString = "466567011.456365"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "77"
endingLineNumber = "77"
landmarkName = "deinit"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "MeiPaiDemo/RecordVideoView.swift"
timestampString = "466582861.375422"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "387"
endingLineNumber = "387"
landmarkName = "recordRealTimeFilterVideoToOutputFileURL(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "MeiPaiDemo/RecordVideoView.swift"
timestampString = "466582919.378101"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "406"
endingLineNumber = "406"
landmarkName = "recordRealTimeFilterVideoPerFrame(_:outputImage:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "MeiPaiDemo/RecordModel.swift"
timestampString = "466583405.212742"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "178"
endingLineNumber = "178"
landmarkName = "deleteTempVideo()"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "MeiPaiDemo/FilterScrollView.swift"
timestampString = "466764093.719284"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "39"
endingLineNumber = "39"
landmarkName = "initScrollView()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "MeiPaiDemo/FilterScrollView.swift"
timestampString = "466824087.114788"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "62"
endingLineNumber = "62"
landmarkName = "initView()"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
21 changes: 21 additions & 0 deletions MeiPaiDemo/MeiPaiDemo/Assets.xcassets/back.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 4 additions & 11 deletions MeiPaiDemo/MeiPaiDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,13 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="G1g-q8-jxD" userLabel="Record Button">
<rect key="frame" x="260" y="505" width="80" height="80"/>
<color key="backgroundColor" red="1" green="0.40000000600000002" blue="0.40000000600000002" alpha="1" colorSpace="calibratedRGB"/>
<rect key="frame" x="265" y="515" width="70" height="70"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="80" id="q7X-NG-Beh"/>
<constraint firstAttribute="width" constant="80" id="yJx-ZQ-myg"/>
<constraint firstAttribute="height" constant="70" id="q7X-NG-Beh"/>
<constraint firstAttribute="width" constant="70" id="yJx-ZQ-myg"/>
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="tCK-Np-p0T">
<rect key="frame" x="57" y="521" width="46" height="30"/>
<state key="normal" title="Button"/>
<connections>
<action selector="changeCameraMode:" destination="lGr-AR-c4X" eventType="touchUpInside" id="QHD-5f-fTb"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand Down
14 changes: 14 additions & 0 deletions MeiPaiDemo/MeiPaiDemo/Common.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Common.swift
// MeiPaiDemo
//
// Created by 陈智颖 on 15/10/18.
// Copyright © 2015年 YY. All rights reserved.
//

import Foundation
import UIKit

struct CommonColor {
static let mainColor = UIColor(red: 255/255, green: 102/255, blue: 102/255, alpha: 1)
}
88 changes: 88 additions & 0 deletions MeiPaiDemo/MeiPaiDemo/FilterScrollView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// FilterScrollView.swift
// MeiPaiDemo
//
// Created by 陈智颖 on 15/10/17.
// Copyright © 2015年 YY. All rights reserved.
//

import UIKit

class FilterScrollView: UIView {

private var scrollView: UIScrollView!
private var filterLabels = [UILabel]()

private var filters = [CIFilter?]()
private var currentFilterIndex = 0
private let maxCountInScreen = 3

// MARK: - Life Cycle
private override init(frame: CGRect) {
super.init(frame: frame)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

convenience init(frame: CGRect, filters: [CIFilter?]) {
self.init(frame: frame)

self.filters = filters
initView()
}

func initView() {

func initScrollView() {
scrollView = UIScrollView(frame: CGRectMake(frame.origin.x + frame.size.width / CGFloat(maxCountInScreen) , 0, frame.size.width / CGFloat(maxCountInScreen), frame.size.height))
scrollView.scrollEnabled = false
scrollView.clipsToBounds = false
}

func changeFilterToLabel() {
guard filters.count > 0 else { return }
var count = 0
filterLabels = filters.map { filter -> UILabel in
let label = UILabel(frame: CGRectMake(scrollView.frame.width * CGFloat(count++) , 0, scrollView.frame.width, scrollView.frame.height))
label.text = filter == nil ? "Normal" : (filter!.name as NSString).substringFromIndex(13)
label.textColor = UIColor.grayColor()
label.font = UIFont.systemFontOfSize(13)
label.textAlignment = .Center
scrollView.addSubview(label)
return label
}

filterLabels[currentFilterIndex].textColor = CommonColor.mainColor
filterLabels[currentFilterIndex].font = UIFont.systemFontOfSize(15)
}

initScrollView()
changeFilterToLabel()
scrollView.contentSize = CGSizeMake(CGFloat(filterLabels.count) * scrollView.frame.width, scrollView.frame.height)
addSubview(scrollView)

}

// MARK: - Public
func changeFIlterByPlus(plus: Bool) {

filterLabels[currentFilterIndex].textColor = UIColor.grayColor()
filterLabels[currentFilterIndex].font = UIFont.systemFontOfSize(13)

if plus {
guard currentFilterIndex < filterLabels.count - 1 else { return }
currentFilterIndex++
} else {
guard currentFilterIndex > 0 else { return }
currentFilterIndex--
}

filterLabels[currentFilterIndex].textColor = CommonColor.mainColor
filterLabels[currentFilterIndex].font = UIFont.systemFontOfSize(15)
scrollView.setContentOffset(CGPointMake(CGFloat(currentFilterIndex) * scrollView.frame.width, 0), animated: true)

}

}
2 changes: 1 addition & 1 deletion MeiPaiDemo/MeiPaiDemo/RealTimeFilterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RealTimeFilterView: GLKView {
guard let image = self.image else { return }

let scale = self.window?.screen.scale ?? 1.0
let destRect = CGRectApplyAffineTransform(bounds, CGAffineTransformMakeScale(scale, scale))
let destRect = CGRectApplyAffineTransform(UIScreen.mainScreen().bounds, CGAffineTransformMakeScale(scale, scale))
ciContext.drawImage(image, inRect: destRect, fromRect: image.extent)
}

Expand Down
Loading

0 comments on commit 49df353

Please sign in to comment.