panInContentView----左右菜单控制函数
- (void)panInContentView:(UIPanGestureRecognizer *)panGestureReconginzer
{
if (panGestureReconginzer.state == UIGestureRecognizerStateChanged)
{
CGFloat translation = [panGestureReconginzer translationInView:self.contentView].x;
self.contentView.transform = CGAffineTransformMakeTranslation(translation+currentTranslate, 0);
UIView *view ;
if (translation+currentTranslate>0)
{
view = self.leftSideBarViewController.view;
}
else
{
view = self.rightSideBarViewController.view;
}
[self.navBackView bringSubviewToFront:view];
} else if (panGestureReconginzer.state == UIGestureRecognizerStateEnded)
{
currentTranslate = self.contentView.transform.tx;
if (!sideBarShowing)//开
{
if (fabs(currentTranslate)<ContentMinOffset)
{
[self moveAnimationWithDirection:SideBarShowDirectionNone duration:MoveAnimationDuration];
}else if(currentTranslate>ContentMinOffset)
{
[self moveAnimationWithDirection:SideBarShowDirectionLeft duration:MoveAnimationDuration];
}
else
{
[self moveAnimationWithDirection:SideBarShowDirectionRight duration:MoveAnimationDuration];
}
}
else //关
{
if (fabs(currentTranslate)<ContentChangeset)
{
[self moveAnimationWithDirection:SideBarShowDirectionNone duration:MoveAnimationDuration];
}
else if(currentTranslate>ContentChangeset)
{
[self moveAnimationWithDirection:SideBarShowDirectionLeft duration:MoveAnimationDuration];
}
else
{
[self moveAnimationWithDirection:SideBarShowDirectionRight duration:MoveAnimationDuration];
}
}
}
}
2.只要左菜单
- (void)panInContentView:(UIPanGestureRecognizer *)panGestureReconginzer
{
if (panGestureReconginzer.state == UIGestureRecognizerStateChanged)
{
CGFloat translation = [panGestureReconginzer translationInView:self.contentView].x;
self.contentView.transform = CGAffineTransformMakeTranslation(translation+currentTranslate, 0);
UIView *view ;
view = self.leftSideBarViewController.view;
[self.navBackView bringSubviewToFront:view];
} else if (panGestureReconginzer.state == UIGestureRecognizerStateEnded)
{
currentTranslate = self.contentView.transform.tx;
if (!sideBarShowing)//开
{
if (currentTranslate>ContentMinOffset)
{
[self moveAnimationWithDirection:SideBarShowDirectionLeft duration:MoveAnimationDuration];
}
else
{
[self moveAnimationWithDirection:SideBarShowDirectionNone duration:MoveAnimationDuration];
}
}
else //关
{
[self moveAnimationWithDirection:SideBarShowDirectionNone duration:MoveAnimationDuration];
}
}
}
3.只要右边
- (void)panInContentView:(UIPanGestureRecognizer *)panGestureReconginzer
{
if (panGestureReconginzer.state == UIGestureRecognizerStateChanged)
{
CGFloat translation = [panGestureReconginzer translationInView:self.contentView].x;
self.contentView.transform = CGAffineTransformMakeTranslation(translation+currentTranslate, 0);
UIView *view ;
view = self.rightSideBarViewController.view;
[self.navBackView bringSubviewToFront:view];
} else if (panGestureReconginzer.state == UIGestureRecognizerStateEnded)
{
currentTranslate = self.contentView.transform.tx;
if (!sideBarShowing)//开
{
if(currentTranslate<ContentMinOffset)
{
[self moveAnimationWithDirection:SideBarShowDirectionRight duration:MoveAnimationDuration];
}
else
{
[self moveAnimationWithDirection:SideBarShowDirectionNone duration:MoveAnimationDuration];
}
}
else //关
{
[self moveAnimationWithDirection:SideBarShowDirectionNone duration:MoveAnimationDuration];
}
}
}
综合写法
- (void)panInContentView:(UIPanGestureRecognizer *)panGestureReconginzer
{
if (panGestureReconginzer.state == UIGestureRecognizerStateChanged)
{
CGFloat translation = [panGestureReconginzer translationInView:self.contentView].x;
self.contentView.transform = CGAffineTransformMakeTranslation(translation+currentTranslate, 0);
UIView *view ;
if(isOpenRight==YES&&isOpenLeft==YES)
{
if (translation+currentTranslate>0)
{
view = self.leftSideBarViewController.view;
}
else
{
view = self.rightSideBarViewController.view;
}
}
else if(isOpenLeft==YES&&isOpenRight==NO)
{
view = self.leftSideBarViewController.view;
}
else if(isOpenLeft==NO&&isOpenRight==YES)
{
view = self.rightSideBarViewController.view;
}
[self.navBackView bringSubviewToFront:view];
} else if (panGestureReconginzer.state == UIGestureRecognizerStateEnded)
{
currentTranslate = self.contentView.transform.tx;
if (!sideBarShowing)//开
{
if(isOpenRight==YES&&isOpenLeft==YES)
{
if (fabs(currentTranslate)<ContentMinOffset)
{
[self moveAnimationWithDirection:SideBarShowDirectionNone duration:MoveAnimationDuration];
}else if(currentTranslate>ContentMinOffset)
{
[self moveAnimationWithDirection:SideBarShowDirectionLeft duration:MoveAnimationDuration];
}
else
{
[self moveAnimationWithDirection:SideBarShowDirectionRight duration:MoveAnimationDuration];
}
}
else if(isOpenLeft==YES&&isOpenRight==NO)
{
if(currentTranslate>ContentMinOffset)
{
[self moveAnimationWithDirection:SideBarShowDirectionLeft duration:MoveAnimationDuration];
}
else
{
[self moveAnimationWithDirection:SideBarShowDirectionNone duration:MoveAnimationDuration];
}
}
else if(isOpenLeft==NO&&isOpenRight==YES)
{
if(currentTranslate<ContentMinOffset)
{
[self moveAnimationWithDirection:SideBarShowDirectionRight duration:MoveAnimationDuration];
}
else
{
[self moveAnimationWithDirection:SideBarShowDirectionNone duration:MoveAnimationDuration];
}
}
}
else //关
{
if(isOpenRight==YES&&isOpenLeft==YES)
{
if (fabs(currentTranslate)<ContentChangeset)
{
[self moveAnimationWithDirection:SideBarShowDirectionNone duration:MoveAnimationDuration];
}
else if(currentTranslate>ContentChangeset)
{
[self moveAnimationWithDirection:SideBarShowDirectionLeft duration:MoveAnimationDuration];
}
else
{
[self moveAnimationWithDirection:SideBarShowDirectionRight duration:MoveAnimationDuration];
}
}
else{
[self moveAnimationWithDirection:SideBarShowDirectionNone duration:MoveAnimationDuration];
}
}
}
}