Sidebar 左右菜单的使用

简介: 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];  
            }
        }
  }
}
相关文章
|
7月前
命令菜单
命令菜单
39 2
|
7月前
Qt实现的多菜单选择界面
Qt实现的多菜单选择界面
109 0
09EasyUI 菜单与按钮- 创建简单的菜单
09EasyUI 菜单与按钮- 创建简单的菜单
35 0
electron菜单或托盘点击如何打开新的窗口
electron菜单或托盘点击如何打开新的窗口
electron菜单或托盘点击如何打开新的窗口
|
Java
swing做一个简单的记事本(有菜单的样式、右键弹出菜单、以及实现“新建”和“打开”功能)
swing做一个简单的记事本(有菜单的样式、右键弹出菜单、以及实现“新建”和“打开”功能)
356 0
swing做一个简单的记事本(有菜单的样式、右键弹出菜单、以及实现“新建”和“打开”功能)
侧边栏菜单导航
在线演示 本地下载
1238 0
|
区块链 Python 数据格式