Skip to content

Commit

Permalink
Fixed issue #104:
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoa committed Jan 5, 2014
1 parent cabdd23 commit 82b8aea
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 20 deletions.
12 changes: 6 additions & 6 deletions SASlideMenu.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SASlideMenuiPad/SASlideMenuiPad-Prefix.pch";
INFOPLIST_FILE = "SASlideMenuiPad/SASlideMenuiPad-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.1;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -770,7 +770,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SASlideMenuiPad/SASlideMenuiPad-Prefix.pch";
INFOPLIST_FILE = "SASlideMenuiPad/SASlideMenuiPad-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.1;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
Expand Down Expand Up @@ -852,7 +852,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SASlideMenuDynamic/SASlideMenuDynamic-Prefix.pch";
INFOPLIST_FILE = "SASlideMenuDynamic/SASlideMenuDynamic-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.1;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -871,7 +871,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SASlideMenuDynamic/SASlideMenuDynamic-Prefix.pch";
INFOPLIST_FILE = "SASlideMenuDynamic/SASlideMenuDynamic-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.1;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
Expand All @@ -889,7 +889,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SASlideMenuStatic/SASlideMenuStatic-Prefix.pch";
INFOPLIST_FILE = "SASlideMenuStatic/SASlideMenuStatic-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.1;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
Expand All @@ -907,7 +907,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SASlideMenuStatic/SASlideMenuStatic-Prefix.pch";
INFOPLIST_FILE = "SASlideMenuStatic/SASlideMenuStatic-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.1;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand Down
64 changes: 56 additions & 8 deletions SASlideMenu/SASlideMenu/SASlideMenuRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
SASlideMenuPanningStateLeft
} SASlideMenuPanningState;

@interface SASlideMenuRootViewController (){
@interface SASlideMenuRootViewController ()<UIDynamicAnimatorDelegate>{
SASlideMenuState state;
SASlideMenuPanningState panningState;
CGFloat panningPreviousPosition;
Expand All @@ -37,11 +37,17 @@ @interface SASlideMenuRootViewController (){

UIPanGestureRecognizer* menuPanGesture;
UITapGestureRecognizer* tapGesture;

UIDynamicAnimator *animator;
UICollisionBehavior *collisionBehaviour;
UIPushBehavior *pushBehavior;
UIGravityBehavior *gravityBehavior;
}

@property (nonatomic,strong) UINavigationController* selectedContent;
@property (nonatomic, strong) UIView* shieldWithMenu;


@end

#define kSlideInInterval 0.3
Expand Down Expand Up @@ -191,6 +197,7 @@ -(void) doSlideIn:(void (^)(BOOL completed))completion{
[self.leftMenu.slideMenuDelegate slideMenuWillSlideIn:self.selectedContent];
}
[self disableGestureRecognizers];

CGFloat duration = kSlideInInterval;
if ([self.leftMenu.slideMenuDataSource respondsToSelector:@selector(slideInAnimationDuration)]) {
duration = [self.leftMenu.slideMenuDataSource slideInAnimationDuration];
Expand All @@ -212,6 +219,7 @@ -(void) doSlideIn:(void (^)(BOOL completed))completion{
}
[self enableGestureRecognizers];
}];

}

- (void)disableGestureRecognizers {
Expand Down Expand Up @@ -254,6 +262,21 @@ -(void) tapShield:(UITapGestureRecognizer*)gesture{
-(void) tapItem:(UITapGestureRecognizer*)gesture{
[self switchToContentViewController:self.selectedContent completion:nil];
}
#pragma mark --
#pragma mark UIDynamicAnimatorDelegate
- (void)dynamicAnimatorDidPause:(UIDynamicAnimator *)a{
[animator removeAllBehaviors];
if (panningState == SASlideMenuPanningStateLeft
|| state == SASlideMenuStateRightMenu) {
[self removeRightMenu];
}
[self completeSlideIn:self.selectedContent];
[self enableGestureRecognizers];

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

}

-(void) panItem:(UIPanGestureRecognizer*)gesture{
UIView* panningView = gesture.view;
Expand All @@ -279,15 +302,35 @@ -(void) panItem:(UIPanGestureRecognizer*)gesture{
// - The move speed is high enough.
// - The move speed is not high enough, but the view has been dragged more than half of the way to the side.
CGFloat originx = movingView.frame.origin.x;
CGFloat t =self.selectedContent.view.frame.origin.x;
CGFloat limit = self.view.frame.size.width/2;
if (panningState == SASlideMenuPanningStateRight) {
if (panningXSpeed < -kSwipeMinDetectionSpeed) {
[self doSlideIn:nil];
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];
[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;


[animator addBehavior:pushBehavior];

} else if (panningXSpeed > kSwipeMinDetectionSpeed) {
[self doSlideToSide];
} else if (originx < [self leftMenuSize] / 2.0f) {
[self doSlideIn:nil];
} else {
[self doSlideToSide];
}
}
if (panningState == SASlideMenuPanningStateLeft) {
Expand Down Expand Up @@ -487,11 +530,16 @@ - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInte
}
}

-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
-(void) viewDidLoad{
[super viewDidLoad];

controllers = [[NSMutableDictionary alloc] init];

animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
animator.delegate = self;

self.shieldWithMenu = [[UIView alloc] initWithFrame:CGRectZero];
state = SASlideMenuStateInitial;
panningState = SASlideMenuPanningStateStopped;
Expand Down
7 changes: 1 addition & 6 deletions SASlideMenu/SASlideMenu/SASlideMenuViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ -(id)init; {

- (void)loadContentAtIndexPath:(NSIndexPath*)indexPath {
if ([self.slideMenuDataSource respondsToSelector:@selector(segueIdForIndexPath:)]) {
self.currentContentIndexPath = indexPath;
UINavigationController* controller = [self.rootController controllerForIndexPath:indexPath];
if (controller) {
[self.rootController switchToContentViewController:controller completion:nil];
return;
}
NSString* segueId = [self.slideMenuDataSource segueIdForIndexPath:indexPath];
[self performSegueWithIdentifier:segueId sender:self];
self.currentContentIndexPath = indexPath;
}
}

Expand All @@ -59,11 +59,6 @@ -(void)selectContentAtIndexPath:(NSIndexPath *)indexPath scrollPosition:(UITable
if ([self.slideMenuDataSource respondsToSelector:@selector(segueIdForIndexPath:)]) {
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:scrollPosition];

Boolean disableContentViewControllerCaching= NO;
if ([self.slideMenuDataSource respondsToSelector:@selector(disableContentViewControllerCachingForIndexPath:)]) {
disableContentViewControllerCaching = [self.slideMenuDataSource disableContentViewControllerCachingForIndexPath:indexPath];
}

[self loadContentAtIndexPath:indexPath];
}
}
Expand Down

0 comments on commit 82b8aea

Please sign in to comment.