Commit 8d3872d1 by Daniel Dahan

updated SideNavigationViewController to use unowned self within blocks. SideView…

updated SideNavigationViewController to use unowned self within blocks. SideView is now initialized in prepareSideView rather than lazy loaded
parent fdbe744f
......@@ -7,24 +7,24 @@
objects = {
/* Begin PBXBuildFile section */
9637D2141C25F7FF00BCAF93 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9637D2131C25F7FF00BCAF93 /* MaterialKit.framework */; };
9637D2151C25F7FF00BCAF93 /* MaterialKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9637D2131C25F7FF00BCAF93 /* MaterialKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9642FA1B1C1B50E700022BC6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA1A1C1B50E700022BC6 /* AppDelegate.swift */; };
9642FA1D1C1B50E700022BC6 /* AMainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA1C1C1B50E700022BC6 /* AMainViewController.swift */; };
9642FA221C1B50E700022BC6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9642FA211C1B50E700022BC6 /* Assets.xcassets */; };
9642FA251C1B50E700022BC6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9642FA231C1B50E700022BC6 /* LaunchScreen.storyboard */; };
9642FA311C1B906600022BC6 /* BMainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA301C1B906600022BC6 /* BMainViewController.swift */; };
9642FA331C1B909700022BC6 /* SideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9642FA321C1B909700022BC6 /* SideViewController.swift */; };
96668B1C1C29C8F5001916C7 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96668B1B1C29C8F5001916C7 /* MaterialKit.framework */; };
96668B1D1C29C8F5001916C7 /* MaterialKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 96668B1B1C29C8F5001916C7 /* MaterialKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
9642FA2F1C1B516F00022BC6 /* Embed Frameworks */ = {
96668B1E1C29C8F5001916C7 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
9637D2151C25F7FF00BCAF93 /* MaterialKit.framework in Embed Frameworks */,
96668B1D1C29C8F5001916C7 /* MaterialKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -32,7 +32,6 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
9637D2131C25F7FF00BCAF93 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MaterialKit.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-anypxbsecgdqqxevbavirvnffqxd/Build/Products/Debug-iphoneos/MaterialKit.framework"; sourceTree = "<absolute>"; };
9642FA171C1B50E700022BC6 /* SideNavigationViewController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SideNavigationViewController.app; sourceTree = BUILT_PRODUCTS_DIR; };
9642FA1A1C1B50E700022BC6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
9642FA1C1C1B50E700022BC6 /* AMainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AMainViewController.swift; sourceTree = "<group>"; };
......@@ -41,6 +40,7 @@
9642FA261C1B50E700022BC6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9642FA301C1B906600022BC6 /* BMainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BMainViewController.swift; sourceTree = "<group>"; };
9642FA321C1B909700022BC6 /* SideViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideViewController.swift; sourceTree = "<group>"; };
96668B1B1C29C8F5001916C7 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = MaterialKit.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/MaterialKit-anypxbsecgdqqxevbavirvnffqxd/Build/Products/Debug-iphoneos/MaterialKit.framework"; sourceTree = "<absolute>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -48,7 +48,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9637D2141C25F7FF00BCAF93 /* MaterialKit.framework in Frameworks */,
96668B1C1C29C8F5001916C7 /* MaterialKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -58,7 +58,7 @@
9642FA0E1C1B50E700022BC6 = {
isa = PBXGroup;
children = (
9637D2131C25F7FF00BCAF93 /* MaterialKit.framework */,
96668B1B1C29C8F5001916C7 /* MaterialKit.framework */,
9642FA191C1B50E700022BC6 /* SideNavigationViewController */,
9642FA181C1B50E700022BC6 /* Products */,
);
......@@ -96,7 +96,7 @@
9642FA131C1B50E700022BC6 /* Sources */,
9642FA141C1B50E700022BC6 /* Frameworks */,
9642FA151C1B50E700022BC6 /* Resources */,
9642FA2F1C1B516F00022BC6 /* Embed Frameworks */,
96668B1E1C29C8F5001916C7 /* Embed Frameworks */,
);
buildRules = (
);
......
......@@ -132,11 +132,11 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
public lazy var hideStatusBar: Bool = true
/**
:name: enableShadowDepth
:name: depthEnabled
*/
public var enableShadowDepth: Bool = true {
public var depthEnabled: Bool = true {
didSet {
if !enableShadowDepth {
if !depthEnabled {
sideView.depth = .None
}
}
......@@ -147,7 +147,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
*/
public var depth: MaterialDepth = .Depth2 {
didSet {
if !enableShadowDepth && .None != sideView.depth {
if !depthEnabled && .None != sideView.depth {
sideView.depth = depth
}
}
......@@ -161,7 +161,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/**
:name: sideView
*/
public private(set) lazy var sideView: MaterialView = MaterialView()
public private(set) var sideView: MaterialView!
/**
:name: backdropOpacity
......@@ -259,16 +259,16 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
let w: CGFloat = (hidden ? -width : width) / 2
if animated {
MaterialAnimation.animateWithDuration(0.25, animations: { [unowned sideView = self.sideView] in
sideView.width = width
sideView.position.x = w
MaterialAnimation.animateWithDuration(0.25, animations: { [unowned self] in
self.sideView.width = width
self.sideView.position.x = w
}) { [unowned self] in
self.userInteractionEnabled = false
}
} else {
MaterialAnimation.animationDisabled { [unowned sideView = self.sideView] in
sideView.width = width
sideView.position.x = w
MaterialAnimation.animationDisabled { [unowned self] in
self.sideView.width = width
self.sideView.position.x = w
}
}
}
......@@ -290,18 +290,18 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
delegate?.sideNavigationViewWillOpen?(self)
MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(sideView.x / velocity)))),
animations: { [unowned sideView = self.sideView] in
sideView.position = CGPointMake(sideView.width / 2, sideView.height / 2)
}) { [unowned self, weak delegate = self.delegate] in
animations: { [unowned self] in
self.sideView.position = CGPointMake(self.sideView.width / 2, self.sideView.height / 2)
}) { [unowned self] in
self.userInteractionEnabled = false
if self.enableShadowDepth {
MaterialAnimation.animationDisabled { [unowned self, unowned sideView = self.sideView] in
sideView.depth = self.depth
if self.depthEnabled {
MaterialAnimation.animationDisabled { [unowned self] in
self.sideView.depth = self.depth
}
}
delegate?.sideNavigationViewDidOpen?(self)
self.delegate?.sideNavigationViewDidOpen?(self)
}
}
......@@ -315,18 +315,18 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
delegate?.sideNavigationViewWillClose?(self)
MaterialAnimation.animateWithDuration(Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(sideView.x / velocity)))),
animations: { [unowned sideView = self.sideView] in
sideView.position = CGPointMake(-sideView.width / 2, sideView.height / 2)
}) { [unowned self, weak delegate = self.delegate] in
animations: { [unowned self] in
self.sideView.position = CGPointMake(-self.sideView.width / 2, self.sideView.height / 2)
}) { [unowned self] in
self.userInteractionEnabled = true
if self.enableShadowDepth {
MaterialAnimation.animationDisabled { [unowned sideView = self.sideView] in
sideView.depth = .None
if self.depthEnabled {
MaterialAnimation.animationDisabled { [unowned self] in
self.sideView.depth = .None
}
}
delegate?.sideNavigationViewDidClose?(self)
self.delegate?.sideNavigationViewDidClose?(self)
}
}
......@@ -338,7 +338,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
if gestureRecognizer == sidePanGesture {
return gesturePanSideViewController(gestureRecognizer, withTouchPoint: touch.locationInView(view))
}
if gestureRecognizer == sideTapGesture && opened {
if opened && gestureRecognizer == sideTapGesture {
let point: CGPoint = touch.locationInView(view)
delegate?.sideNavigationViewDidTap?(self, point: point)
return !isPointContainedWithinViewController(sideView, point: point)
......@@ -374,14 +374,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
:name: prepareSideView
*/
internal func prepareSideView() {
// container
sideView = MaterialView()
sideView.frame = CGRectMake(0, 0, sideViewControllerWidth, view.frame.height)
sideView.backgroundColor = MaterialColor.clear
view.addSubview(sideView)
MaterialAnimation.animationDisabled { [unowned self, unowned sideView = self.sideView] in
sideView.position.x = -self.sideViewControllerWidth / 2
sideView.zPosition = 1000
MaterialAnimation.animationDisabled { [unowned self] in
self.sideView.position.x = -self.sideViewControllerWidth / 2
self.sideView.zPosition = 1000
}
prepareSideViewController()
......@@ -397,7 +397,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
backdropLayer.hidden = false
originalPosition = sideView.position
toggleStatusBar(true)
if enableShadowDepth {
if depthEnabled {
MaterialAnimation.animationDisabled { [unowned self, sideView = self.sideView] in
sideView.depth = self.depth
}
......@@ -407,9 +407,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
let translation: CGPoint = recognizer.translationInView(sideView)
let w: CGFloat = sideView.width
MaterialAnimation.animationDisabled { [unowned self, weak delegate = self.delegate, unowned sideView = self.sideView] in
sideView.position.x = self.originalPosition.x + translation.x > (w / 2) ? (w / 2) : self.originalPosition.x + translation.x
delegate?.sideNavigationViewPanDidChange?(self, point: sideView.position)
MaterialAnimation.animationDisabled { [unowned self] in
self.sideView.position.x = self.originalPosition.x + translation.x > (w / 2) ? (w / 2) : self.originalPosition.x + translation.x
self.delegate?.sideNavigationViewPanDidChange?(self, point: self.sideView.position)
}
case .Ended, .Cancelled, .Failed:
let point: CGPoint = recognizer.velocityInView(recognizer.view)
......
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