Commit 66f04237 by Daniel Dahan

updated example App

parent eac04161
...@@ -46,6 +46,7 @@ class AppSearchBarViewController: SearchBarViewController { ...@@ -46,6 +46,7 @@ class AppSearchBarViewController: SearchBarViewController {
override func viewWillDisappear(animated: Bool) { override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated) super.viewWillDisappear(animated)
sideNavigationViewController?.enabled = true sideNavigationViewController?.enabled = true
searchBarView.textField.resignFirstResponder()
} }
override func viewWillAppear(animated: Bool) { override func viewWillAppear(animated: Bool) {
...@@ -53,6 +54,7 @@ class AppSearchBarViewController: SearchBarViewController { ...@@ -53,6 +54,7 @@ class AppSearchBarViewController: SearchBarViewController {
searchBarView.statusBarStyle = .Default searchBarView.statusBarStyle = .Default
sideNavigationViewController?.delegate = self sideNavigationViewController?.delegate = self
sideNavigationViewController?.enabled = false sideNavigationViewController?.enabled = false
searchBarView.textField.becomeFirstResponder()
} }
/// Toggle SideSearchViewController left UIViewController. /// Toggle SideSearchViewController left UIViewController.
...@@ -71,7 +73,6 @@ class AppSearchBarViewController: SearchBarViewController { ...@@ -71,7 +73,6 @@ class AppSearchBarViewController: SearchBarViewController {
override func prepareView() { override func prepareView() {
super.prepareView() super.prepareView()
view.backgroundColor = MaterialColor.black view.backgroundColor = MaterialColor.black
searchBarView.textField.becomeFirstResponder()
} }
/// Prepares the searchBarView. /// Prepares the searchBarView.
......
...@@ -53,7 +53,7 @@ class FeedViewController: UIViewController { ...@@ -53,7 +53,7 @@ class FeedViewController: UIViewController {
/// Prepares view. /// Prepares view.
private func prepareView() { private func prepareView() {
view.backgroundColor = MaterialColor.grey.lighten5 view.backgroundColor = MaterialColor.grey.lighten4
} }
/// Prepares the collectionView /// Prepares the collectionView
...@@ -165,7 +165,7 @@ extension FeedViewController: MaterialCollectionViewDataSource { ...@@ -165,7 +165,7 @@ extension FeedViewController: MaterialCollectionViewDataSource {
c.controlView = ControlView() c.controlView = ControlView()
c.controlView!.backgroundColor = nil c.controlView!.backgroundColor = nil
// Create a date UILabel for the ControlView's contentView.
let date: UILabel = UILabel() let date: UILabel = UILabel()
date.font = RobotoFont.regularWithSize(12) date.font = RobotoFont.regularWithSize(12)
date.textColor = MaterialColor.grey.base date.textColor = MaterialColor.grey.base
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
96A71ED71C6FFF7300C0C4AE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71ED61C6FFF7300C0C4AE /* ViewController.swift */; }; 96A71ED71C6FFF7300C0C4AE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71ED61C6FFF7300C0C4AE /* ViewController.swift */; };
96A71EDC1C6FFF7300C0C4AE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96A71EDB1C6FFF7300C0C4AE /* Assets.xcassets */; }; 96A71EDC1C6FFF7300C0C4AE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96A71EDB1C6FFF7300C0C4AE /* Assets.xcassets */; };
96A71EDF1C6FFF7300C0C4AE /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96A71EDD1C6FFF7300C0C4AE /* LaunchScreen.storyboard */; }; 96A71EDF1C6FFF7300C0C4AE /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96A71EDD1C6FFF7300C0C4AE /* LaunchScreen.storyboard */; };
96CC08851C7FC2710034FF84 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96CC08841C7FC2710034FF84 /* Material.framework */; }; 96D527F01C81566500D3BDD1 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96D527EF1C81566500D3BDD1 /* Material.framework */; };
96CC08861C7FC2710034FF84 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96CC08841C7FC2710034FF84 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 96D527F11C81566500D3BDD1 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96D527EF1C81566500D3BDD1 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
96CC08861C7FC2710034FF84 /* Material.framework in Embed Frameworks */, 96D527F11C81566500D3BDD1 /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
96A71EDB1C6FFF7300C0C4AE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 96A71EDB1C6FFF7300C0C4AE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
96A71EDE1C6FFF7300C0C4AE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 96A71EDE1C6FFF7300C0C4AE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
96A71EE01C6FFF7300C0C4AE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 96A71EE01C6FFF7300C0C4AE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
96CC08841C7FC2710034FF84 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-hbpnflxhoouqxebjcyhbbhqyesjd/Build/Products/Debug-iphoneos/Material.framework"; sourceTree = "<absolute>"; }; 96D527EF1C81566500D3BDD1 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-hbpnflxhoouqxebjcyhbbhqyesjd/Build/Products/Debug-iphoneos/Material.framework"; sourceTree = "<absolute>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
96CC08851C7FC2710034FF84 /* Material.framework in Frameworks */, 96D527F01C81566500D3BDD1 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
96A71EC81C6FFF7300C0C4AE = { 96A71EC81C6FFF7300C0C4AE = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96CC08841C7FC2710034FF84 /* Material.framework */, 96D527EF1C81566500D3BDD1 /* Material.framework */,
96A71ED31C6FFF7300C0C4AE /* MaterialSwitch */, 96A71ED31C6FFF7300C0C4AE /* MaterialSwitch */,
96A71ED21C6FFF7300C0C4AE /* Products */, 96A71ED21C6FFF7300C0C4AE /* Products */,
); );
......
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
96CC089B1C80B82E0034FF84 /* BasicCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */; }; 96CC089B1C80B82E0034FF84 /* BasicCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */; };
96CC089D1C80B8F70034FF84 /* BasicCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */; }; 96CC089D1C80B8F70034FF84 /* BasicCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */; };
96CC08A01C80CB180034FF84 /* MaterialSpacing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC089F1C80CB180034FF84 /* MaterialSpacing.swift */; }; 96CC08A01C80CB180034FF84 /* MaterialSpacing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC089F1C80CB180034FF84 /* MaterialSpacing.swift */; };
96D527EE1C8121EF00D3BDD1 /* BasicCollectionViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D527ED1C8121EF00D3BDD1 /* BasicCollectionViewDataSource.swift */; };
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; }; 96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; };
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; }; 96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; };
96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */; }; 96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */; };
...@@ -184,6 +185,7 @@ ...@@ -184,6 +185,7 @@
96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionView.swift; sourceTree = "<group>"; }; 96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionView.swift; sourceTree = "<group>"; };
96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionViewLayout.swift; sourceTree = "<group>"; }; 96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionViewLayout.swift; sourceTree = "<group>"; };
96CC089F1C80CB180034FF84 /* MaterialSpacing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialSpacing.swift; sourceTree = "<group>"; }; 96CC089F1C80CB180034FF84 /* MaterialSpacing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialSpacing.swift; sourceTree = "<group>"; };
96D527ED1C8121EF00D3BDD1 /* BasicCollectionViewDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCollectionViewDataSource.swift; sourceTree = "<group>"; };
96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.swift; sourceTree = "<group>"; }; 96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.swift; sourceTree = "<group>"; };
96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; }; 96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; };
96D88BF71C1328D800B91418 /* CapturePreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreviewView.swift; sourceTree = "<group>"; }; 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreviewView.swift; sourceTree = "<group>"; };
...@@ -355,6 +357,7 @@ ...@@ -355,6 +357,7 @@
96CC08981C80B74F0034FF84 /* BasicCollectionViewCell.swift */, 96CC08981C80B74F0034FF84 /* BasicCollectionViewCell.swift */,
96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */, 96CC089A1C80B82E0034FF84 /* BasicCollectionView.swift */,
96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */, 96CC089C1C80B8F70034FF84 /* BasicCollectionViewLayout.swift */,
96D527ED1C8121EF00D3BDD1 /* BasicCollectionViewDataSource.swift */,
96CC088B1C7FEC170034FF84 /* MaterialCollectionView.swift */, 96CC088B1C7FEC170034FF84 /* MaterialCollectionView.swift */,
96CC088C1C7FEC170034FF84 /* MaterialCollectionViewCell.swift */, 96CC088C1C7FEC170034FF84 /* MaterialCollectionViewCell.swift */,
96CC088D1C7FEC170034FF84 /* MaterialCollectionViewDataSource.swift */, 96CC088D1C7FEC170034FF84 /* MaterialCollectionViewDataSource.swift */,
...@@ -713,6 +716,7 @@ ...@@ -713,6 +716,7 @@
files = ( files = (
96D88C3D1C1328D800B91418 /* MaterialView.swift in Sources */, 96D88C3D1C1328D800B91418 /* MaterialView.swift in Sources */,
96CC089D1C80B8F70034FF84 /* BasicCollectionViewLayout.swift in Sources */, 96CC089D1C80B8F70034FF84 /* BasicCollectionViewLayout.swift in Sources */,
96D527EE1C8121EF00D3BDD1 /* BasicCollectionViewDataSource.swift in Sources */,
960B23481C38480E00E96216 /* TextView.swift in Sources */, 960B23481C38480E00E96216 /* TextView.swift in Sources */,
96D88C291C1328D800B91418 /* MaterialBasicAnimation.swift in Sources */, 96D88C291C1328D800B91418 /* MaterialBasicAnimation.swift in Sources */,
96D88C3A1C1328D800B91418 /* MaterialTextLayer.swift in Sources */, 96D88C3A1C1328D800B91418 /* MaterialTextLayer.swift in Sources */,
......
...@@ -78,13 +78,6 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell { ...@@ -78,13 +78,6 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
v.removeFromSuperview() v.removeFromSuperview()
} }
grid.views = []
contentView.grid.views = []
contentView.grid.axis.rows = 12
contentView.grid.axis.direction = .Vertical
controlView?.grid.axis.columns = 0 < width ? Int(width / 48) : 12
var a: Int = 0 var a: Int = 0
var b: Int = 0 var b: Int = 0
var c: Int = 0 var c: Int = 0
...@@ -175,11 +168,15 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell { ...@@ -175,11 +168,15 @@ public class BasicCollectionViewCell : MaterialCollectionViewCell {
contentView.grid.views?.append(v) contentView.grid.views?.append(v)
} }
contentView.grid.views = []
contentView.grid.axis.rows = 12
contentView.grid.axis.direction = .Vertical
controlView?.grid.axis.columns = 0 < width ? Int(width / 48) : 12
grid.views = [ grid.views = [
contentView contentView
] ]
contentView.grid.reloadLayout() contentView.grid.reloadLayout()
controlView?.reloadView()
} }
} }
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Material nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public protocol BasicCollectionViewDataSource : MaterialCollectionViewDataSource {}
\ No newline at end of file
...@@ -173,8 +173,6 @@ public class ControlView : MaterialView { ...@@ -173,8 +173,6 @@ public class ControlView : MaterialView {
} }
} }
contentView.grid.columns -= contentView.grid.offset.columns
grid.reloadLayout() grid.reloadLayout()
contentView.grid.reloadLayout() contentView.grid.reloadLayout()
} }
...@@ -195,7 +193,6 @@ public class ControlView : MaterialView { ...@@ -195,7 +193,6 @@ public class ControlView : MaterialView {
/// Prepares the contentView. /// Prepares the contentView.
public func prepareContentView() { public func prepareContentView() {
contentView.backgroundColor = nil contentView.backgroundColor = nil
contentView.grid.axis.direction = .Vertical
addSubview(contentView) addSubview(contentView)
} }
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
public protocol MaterialCollectionViewDataSource : MaterialDelegate, UICollectionViewDataSource { public protocol MaterialCollectionViewDataSource : UICollectionViewDataSource {
/** /**
Retrieves the items for the collectionView. Retrieves the items for the collectionView.
- Returns: An Array of Arrays of MaterialDataSourceItem objects. - Returns: An Array of Arrays of MaterialDataSourceItem objects.
......
...@@ -50,7 +50,6 @@ public protocol MaterialSwitchDelegate { ...@@ -50,7 +50,6 @@ public protocol MaterialSwitchDelegate {
/** /**
A MaterialSwitch delegate method for state changes. A MaterialSwitch delegate method for state changes.
- Parameter control: MaterialSwitch control. - Parameter control: MaterialSwitch control.
- Parameter state: The new state for the control.
*/ */
func materialSwitchStateChanged(control: MaterialSwitch) func materialSwitchStateChanged(control: MaterialSwitch)
} }
...@@ -278,10 +277,9 @@ public class MaterialSwitch: UIControl { ...@@ -278,10 +277,9 @@ public class MaterialSwitch: UIControl {
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
trackLayer = MaterialLayer(frame: CGRectZero) trackLayer = MaterialLayer()
button = FabButton(frame: CGRectZero) button = FabButton()
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView()
prepareTrack() prepareTrack()
prepareButton() prepareButton()
prepareSwitchSize(.Default) prepareSwitchSize(.Default)
...@@ -296,10 +294,9 @@ public class MaterialSwitch: UIControl { ...@@ -296,10 +294,9 @@ public class MaterialSwitch: UIControl {
- Parameter size: A MaterialSwitchSize value. - Parameter size: A MaterialSwitchSize value.
*/ */
public init(state: MaterialSwitchState = .Off, style: MaterialSwitchStyle = .Default, size: MaterialSwitchSize = .Default) { public init(state: MaterialSwitchState = .Off, style: MaterialSwitchStyle = .Default, size: MaterialSwitchSize = .Default) {
trackLayer = MaterialLayer(frame: CGRectZero) trackLayer = MaterialLayer()
button = FabButton(frame: CGRectZero) button = FabButton()
super.init(frame: CGRectZero) super.init(frame: CGRectNull)
prepareView()
prepareTrack() prepareTrack()
prepareButton() prepareButton()
prepareSwitchSize(size) prepareSwitchSize(size)
...@@ -324,17 +321,6 @@ public class MaterialSwitch: UIControl { ...@@ -324,17 +321,6 @@ public class MaterialSwitch: UIControl {
} }
/** /**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public func prepareView() {
addGestureRecognizer(UITapGestureRecognizer(target: self, action: "handleTapped:"))
}
/**
Toggle the MaterialSwitch state, if On will be Off, and if Off will be On. Toggle the MaterialSwitch state, if On will be Off, and if Off will be On.
- Parameter completion: An Optional completion block. - Parameter completion: An Optional completion block.
*/ */
...@@ -363,25 +349,19 @@ public class MaterialSwitch: UIControl { ...@@ -363,25 +349,19 @@ public class MaterialSwitch: UIControl {
if animated { if animated {
animateToState(state) { [unowned self] _ in animateToState(state) { [unowned self] _ in
self.sendActionsForControlEvents(.ValueChanged) self.sendActionsForControlEvents(.ValueChanged)
completion?(control: self)
self.delegate?.materialSwitchStateChanged(self) self.delegate?.materialSwitchStateChanged(self)
} }
} else { } else {
button.x = .On == state ? self.onPosition : self.offPosition button.x = .On == state ? self.onPosition : self.offPosition
styleForState(state) styleForState(state)
sendActionsForControlEvents(.ValueChanged) sendActionsForControlEvents(.ValueChanged)
delegate?.materialSwitchStateChanged(self)
completion?(control: self) completion?(control: self)
delegate?.materialSwitchStateChanged(self)
} }
} }
} }
/// Handles the tap gesture.
internal func handleTapped(recognizer: UITapGestureRecognizer) {
if true == CGRectContainsPoint(trackLayer.frame, layer.convertPoint(recognizer.locationInView(self), fromLayer: layer)) {
setSwitchState(.On == internalSwitchState ? .Off : .On)
}
}
/// Handles the TouchUpInside event. /// Handles the TouchUpInside event.
internal func handleTouchUpInside() { internal func handleTouchUpInside() {
toggle() toggle()
...@@ -392,14 +372,14 @@ public class MaterialSwitch: UIControl { ...@@ -392,14 +372,14 @@ public class MaterialSwitch: UIControl {
- Parameter sender: A UIButton. - Parameter sender: A UIButton.
- Parameter event: A UIEvent. - Parameter event: A UIEvent.
*/ */
internal func handleTouchUpOutsideOrCanceled(sender: FabButton, event: UIEvent) { // internal func handleTouchUpOutsideOrCanceled(sender: FabButton, event: UIEvent) {
if let v: UITouch = event.touchesForView(sender)?.first { // if let v: UITouch = event.touchesForView(sender)?.first {
let t: CGPoint = v.previousLocationInView(sender) // let t: CGPoint = v.previousLocationInView(sender)
let p: CGPoint = v.locationInView(sender) // let p: CGPoint = v.locationInView(sender)
let q: CGFloat = sender.x + p.x - t.x // let q: CGFloat = sender.x + p.x - t.x
setSwitchState(q > (width - button.width) / 2 ? .On : .Off, animated: true) // setSwitchState(q > (width - button.width) / 2 ? .On : .Off, animated: true)
} // }
} // }
/** /**
Handle the TouchDragInside event. Handle the TouchDragInside event.
...@@ -425,10 +405,10 @@ public class MaterialSwitch: UIControl { ...@@ -425,10 +405,10 @@ public class MaterialSwitch: UIControl {
/// Prepares the button. /// Prepares the button.
private func prepareButton() { private func prepareButton() {
button.pulseColor = nil button.pulseColor = nil
button.addTarget(self, action: "handleTouchUpOutsideOrCanceled:event:", forControlEvents: .TouchUpOutside) // button.addTarget(self, action: "handleTouchUpOutsideOrCanceled:event:", forControlEvents: .TouchUpOutside)
button.addTarget(self, action: "handleTouchUpInside", forControlEvents: .TouchUpInside) // button.addTarget(self, action: "handleTouchUpInside", forControlEvents: .TouchUpInside)
button.addTarget(self, action: "handleTouchDragInside:event:", forControlEvents: .TouchDragInside) // button.addTarget(self, action: "handleTouchDragInside:event:", forControlEvents: .TouchDragInside)
button.addTarget(self, action: "handleTouchUpOutsideOrCanceled:event:", forControlEvents: .TouchCancel) // button.addTarget(self, action: "handleTouchUpOutsideOrCanceled:event:", forControlEvents: .TouchCancel)
addSubview(button) addSubview(button)
} }
......
...@@ -93,6 +93,12 @@ public class NavigationBarView : StatusBarView { ...@@ -93,6 +93,12 @@ public class NavigationBarView : StatusBarView {
reloadView() reloadView()
} }
/// Prepares the contentView.
public override func prepareContentView() {
super.prepareContentView()
contentView.grid.axis.direction = .Vertical
}
/// Reloads the view. /// Reloads the view.
public override func reloadView() { public override func reloadView() {
super.reloadView() super.reloadView()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment