Skip to content

Commit

Permalink
Fixed issue #106
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoa committed Jan 18, 2014
1 parent 82b8aea commit 962034f
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 39 deletions.
75 changes: 50 additions & 25 deletions SASlideMenu/SASlideMenu/SASlideMenuRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@
SASlideMenuPanningStateLeft
} SASlideMenuPanningState;

typedef enum {
SASlideMenuContentSlidingOut,
SASlideMenuContentSlidingIn
} SASlideMenuContentSliding;

@interface SASlideMenuRootViewController ()<UIDynamicAnimatorDelegate>{
SASlideMenuState state;
SASlideMenuPanningState panningState;
SASlideMenuContentSliding contentSliding;
CGFloat panningPreviousPosition;
NSDate* panningPreviousEventDate;
CGFloat panningXSpeed; // panning speed expressed in px/ms
Expand Down Expand Up @@ -265,15 +271,29 @@ -(void) tapItem:(UITapGestureRecognizer*)gesture{
#pragma mark --
#pragma mark UIDynamicAnimatorDelegate
- (void)dynamicAnimatorDidPause:(UIDynamicAnimator *)a{
[animator removeAllBehaviors];
if (panningState == SASlideMenuPanningStateLeft
|| state == SASlideMenuStateRightMenu) {
[self removeRightMenu];
if ([animator.behaviors count] >0) {
[animator removeAllBehaviors];

if (panningState == SASlideMenuPanningStateLeft
|| state == SASlideMenuStateRightMenu) {
[self removeRightMenu];
}
if (contentSliding == SASlideMenuContentSlidingIn) {
[self completeSlideIn:self.selectedContent];
if ([self.leftMenu.slideMenuDelegate respondsToSelector:@selector(slideMenuDidSlideIn:)]){
[self.leftMenu.slideMenuDelegate slideMenuDidSlideIn:self.selectedContent];
}
[self enableGestureRecognizers];
}else{
[self completeSlideToSide:self.selectedContent];
if ([self.leftMenu.slideMenuDelegate respondsToSelector:@selector(slideMenuDidSlideToSide:)]){
[self.leftMenu.slideMenuDelegate slideMenuDidSlideToSide:self.selectedContent];
}
[self enableGestureRecognizers];
}
}
[self completeSlideIn:self.selectedContent];
[self enableGestureRecognizers];

}

- (void)dynamicAnimatorWillResume:(UIDynamicAnimator *)animator{

}
Expand Down Expand Up @@ -305,32 +325,37 @@ -(void) panItem:(UIPanGestureRecognizer*)gesture{
CGFloat t =self.selectedContent.view.frame.origin.x;
CGFloat limit = self.view.frame.size.width/2;
if (panningState == SASlideMenuPanningStateRight) {
CGPoint velocity = [gesture velocityInView:self.view];

collisionBehaviour = [[UICollisionBehavior alloc] init];
[collisionBehaviour addItem:self.selectedContent.view];

CGFloat leftMenuWidth = [self leftMenuSize];
[collisionBehaviour setTranslatesReferenceBoundsIntoBoundaryWithInsets:UIEdgeInsetsMake(0, 0, 0, -leftMenuWidth)];

pushBehavior = [[UIPushBehavior alloc] init];
pushBehavior.pushDirection = CGVectorMake(velocity.x, 0);
[pushBehavior addItem:self.selectedContent.view];
pushBehavior.active = YES;
[animator addBehavior:collisionBehaviour];
[animator addBehavior:pushBehavior];

if (t < limit) {
//[self doSlideIn:nil];

CGPoint velocity = [gesture velocityInView:self.view];

gravityBehavior = [[UIGravityBehavior alloc] init];
gravityBehavior.gravityDirection = CGVectorMake(-1, 0);
[gravityBehavior addItem:self.selectedContent.view];
contentSliding = SASlideMenuContentSlidingIn;
[animator addBehavior:gravityBehavior];


collisionBehaviour = [[UICollisionBehavior alloc] init];
[collisionBehaviour addItem:self.selectedContent.view];
[collisionBehaviour setTranslatesReferenceBoundsIntoBoundaryWithInsets:UIEdgeInsetsMake(0, 0, 0, -280)];
[animator addBehavior:collisionBehaviour];

pushBehavior = [[UIPushBehavior alloc] init];
pushBehavior.pushDirection = CGVectorMake(velocity.x, 0);
[pushBehavior addItem:self.selectedContent.view];
pushBehavior.active = YES;

} else {
//[self doSlideToSide];
gravityBehavior = [[UIGravityBehavior alloc] init];
gravityBehavior.gravityDirection = CGVectorMake(1, 0);
[gravityBehavior addItem:self.selectedContent.view];
[animator addBehavior:gravityBehavior];

[animator addBehavior:pushBehavior];

} else if (panningXSpeed > kSwipeMinDetectionSpeed) {
[self doSlideToSide];
contentSliding = SASlideMenuContentSlidingOut;
}
}
if (panningState == SASlideMenuPanningStateLeft) {
Expand Down
4 changes: 2 additions & 2 deletions SASlideMenuDynamic/en.lproj/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4510" systemVersion="12F45" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="Obz-tI-sgf">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4514" systemVersion="12F45" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="Obz-tI-sgf">
<dependencies>
<deployment defaultVersion="1552" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3742"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3747"/>
</dependencies>
<scenes>
<!--Slide Menu Root View Controller-->
Expand Down
6 changes: 3 additions & 3 deletions SASlideMenuStatic/en.lproj/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4510" systemVersion="12F45" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="VKh-QN-AtT">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4514" systemVersion="12F45" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="VKh-QN-AtT">
<dependencies>
<deployment defaultVersion="1552" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3742"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3747"/>
</dependencies>
<scenes>
<!--Slide Menu Root View Controller-->
Expand Down Expand Up @@ -276,7 +276,7 @@
<tableViewCell contentMode="scaleToFill" selectionStyle="gray" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="light" id="SHb-O2-R7e">
<rect key="frame" x="0.0" y="86" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="SHb-O2-R7e">
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="SHb-O2-R7e" id="SpX-G8-Gem">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
Expand Down
Loading

0 comments on commit 962034f

Please sign in to comment.