Sidebar 左右菜单的使用

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];  }}}}

转载于:https://www.cnblogs.com/zzili/archive/2013/01/16/6663186.html

Published by

风君子

独自遨游何稽首 揭天掀地慰生平