Commit e77a0cf2 by Daniel Dahan

updated memory management for Side Nav

parent 69f50f6f
......@@ -23,6 +23,13 @@
</Group>
<Group
location = "container:"
name = "TextField">
<FileRef
location = "group:Programmatic/TextField/TextField.xcodeproj">
</FileRef>
</Group>
<Group
location = "container:"
name = "MaterialView">
<FileRef
location = "group:Programmatic/MaterialView/MaterialView.xcodeproj">
......@@ -77,13 +84,6 @@
location = "group:Programmatic/SideNavigationViewController/SideNavigationViewController.xcodeproj">
</FileRef>
</Group>
<Group
location = "container:"
name = "TextField">
<FileRef
location = "group:Programmatic/TextField/TextField.xcodeproj">
</FileRef>
</Group>
</Group>
<Group
location = "container:"
......
......@@ -7,6 +7,8 @@
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 */; };
......@@ -22,6 +24,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
9637D2151C25F7FF00BCAF93 /* MaterialKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -29,6 +32,7 @@
/* 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>"; };
......@@ -44,6 +48,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9637D2141C25F7FF00BCAF93 /* MaterialKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -53,6 +58,7 @@
9642FA0E1C1B50E700022BC6 = {
isa = PBXGroup;
children = (
9637D2131C25F7FF00BCAF93 /* MaterialKit.framework */,
9642FA191C1B50E700022BC6 /* SideNavigationViewController */,
9642FA181C1B50E700022BC6 /* Products */,
);
......
......@@ -241,12 +241,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
duration: duration,
options: options,
animations: animations,
completion: { (result: Bool) in
self.mainViewController.removeFromParentViewController()
toViewController.didMoveToParentViewController(self)
self.mainViewController = toViewController
self.userInteractionEnabled = !self.opened
completion?(result)
completion: { [unowned self, mainViewController = self.mainViewController] (result: Bool) in
mainViewController.removeFromParentViewController()
toViewController.didMoveToParentViewController(self)
self.mainViewController = toViewController
self.userInteractionEnabled = !self.opened
completion?(result)
})
}
......@@ -259,16 +259,16 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
let w: CGFloat = (hidden ? -width : width) / 2
if animated {
MaterialAnimation.animateWithDuration(0.25, animations: {
self.sideView.width = width
self.sideView.position.x = w
}) {
MaterialAnimation.animateWithDuration(0.25, animations: { [unowned sideView = self.sideView] in
sideView.width = width
sideView.position.x = w
}) { [unowned self] in
self.userInteractionEnabled = false
}
} else {
MaterialAnimation.animationDisabled {
self.sideView.width = width
self.sideView.position.x = w
MaterialAnimation.animationDisabled { [unowned sideView = self.sideView] in
sideView.width = width
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: {
self.sideView.position = CGPointMake(self.sideView.width / 2, self.sideView.height / 2)
}) {
animations: { [unowned sideView = self.sideView] in
sideView.position = CGPointMake(sideView.width / 2, sideView.height / 2)
}) { [unowned self, weak delegate = self.delegate] in
self.userInteractionEnabled = false
if self.enableShadowDepth {
MaterialAnimation.animationDisabled {
self.sideView.shadowDepth = self.shadowDepth
MaterialAnimation.animationDisabled { [unowned self, unowned sideView = self.sideView] in
sideView.shadowDepth = self.shadowDepth
}
}
self.delegate?.sideNavigationViewDidOpen?(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: {
self.sideView.position = CGPointMake(-self.sideView.width / 2, self.sideView.height / 2)
}) {
animations: { [unowned sideView = self.sideView] in
sideView.position = CGPointMake(-sideView.width / 2, sideView.height / 2)
}) { [unowned self, weak delegate = self.delegate] in
self.userInteractionEnabled = true
if self.enableShadowDepth {
MaterialAnimation.animationDisabled {
self.sideView.shadowDepth = .None
MaterialAnimation.animationDisabled { [unowned sideView = self.sideView] in
sideView.shadowDepth = .None
}
}
self.delegate?.sideNavigationViewDidClose?(self)
delegate?.sideNavigationViewDidClose?(self)
}
}
......@@ -334,16 +334,15 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
:name: gestureRecognizer
*/
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if !enabled {
return false
}
if gestureRecognizer == sidePanGesture {
return gesturePanSideViewController(gestureRecognizer, withTouchPoint: touch.locationInView(view))
}
if gestureRecognizer == sideTapGesture && opened {
let point: CGPoint = touch.locationInView(view)
delegate?.sideNavigationViewDidTap?(self, point: point)
return !isPointContainedWithinViewController(sideView, point: point)
if enabled {
if gestureRecognizer == sidePanGesture {
return gesturePanSideViewController(gestureRecognizer, withTouchPoint: touch.locationInView(view))
}
if gestureRecognizer == sideTapGesture && opened {
let point: CGPoint = touch.locationInView(view)
delegate?.sideNavigationViewDidTap?(self, point: point)
return !isPointContainedWithinViewController(sideView, point: point)
}
}
return false
}
......@@ -380,9 +379,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
sideView.backgroundColor = MaterialColor.clear
view.addSubview(sideView)
MaterialAnimation.animationDisabled {
self.sideView.position.x = -self.sideViewControllerWidth / 2
self.sideView.zPosition = 1000
MaterialAnimation.animationDisabled { [unowned self, unowned sideView = self.sideView] in
sideView.position.x = -self.sideViewControllerWidth / 2
sideView.zPosition = 1000
}
prepareSideViewController()
......@@ -399,8 +398,8 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
originalPosition = sideView.position
toggleStatusBar(true)
if enableShadowDepth {
MaterialAnimation.animationDisabled {
self.sideView.shadowDepth = self.shadowDepth
MaterialAnimation.animationDisabled { [unowned self, sideView = self.sideView] in
sideView.shadowDepth = self.shadowDepth
}
}
delegate?.sideNavigationViewPanDidBegin?(self, point: sideView.position)
......@@ -408,9 +407,9 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
let translation: CGPoint = recognizer.translationInView(sideView)
let w: CGFloat = sideView.width
MaterialAnimation.animationDisabled {
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)
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)
}
case .Ended, .Cancelled, .Failed:
let point: CGPoint = recognizer.velocityInView(recognizer.view)
......@@ -519,7 +518,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
:name: layoutBackdropLayer
*/
private func layoutBackdropLayer() {
MaterialAnimation.animationDisabled {
MaterialAnimation.animationDisabled { [unowned self] in
self.backdropLayer.frame = self.view.bounds
}
}
......
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