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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值