仿QQ抽屉效果

2016-01-27  本文已影响1041人  BlueEagleBoy

仿QQ抽屉效果

效果展示:

-QQ效果描述:QQ中的效果是侧滑的效果,当导航控制器从左侧画开的时候,左侧的视图也跟着有稍许的滑动。(注意:在这里左侧View你即可以添加一viewController,也可以添加一个view)。

-(void)panGesture:(UIGestureRecognizer *)gesture {
CGFloat panTouchX = [gesture locationInView:self.view].x;

//当满足手势在哪个范围时才有处罚手势
if (gesture.state == UIGestureRecognizerStateBegan) {
    
    if (panTouchX <= BLEGestureMaxX) {
        
        self.lastPanTouchX = panTouchX;
    }
}
//判断是否满足拖拽条件范围
if (self.lastPanTouchX != 0) {
   
    CGPoint currentPoint = [gesture locationInView:self.view];
    
    CGFloat translateDist = currentPoint.x - self.lastPanTouchX;
    
    CGFloat nextTransformX = self.view.transform.tx + translateDist;
    
    //判断是否会超出左侧view
    if (nextTransformX <= 0) {
        
        self.transformLocation = BLEViewTransformLocationOriginal;
        
        //判断是否会超出左侧预留的宽度范围
    }else if (nextTransformX >= BLETransformMaxW) {
        
        self.transformLocation = BLEViewTransformLocationLeft;
        
    }else {
        
        self.leftView.transform = CGAffineTransformTranslate(self.leftView.transform, translateDist * 0.3, 0);

        self.view.transform = CGAffineTransformTranslate(self.view.transform, translateDist, 0);
    }
    
}

//当拖拽结束的时候会到原始位置
if (gesture.state == UIGestureRecognizerStateEnded) {
    
    self.transformLocation = self.view.transform.tx <  BLETransformMaxW * 0.5 ? BLEViewTransformLocationOriginal : BLEViewTransformLocationLeft;

    self.lastPanTouchX = 0;

}

}


- 遮罩view:当滑动到最右侧后,就添加一个透明遮罩,点击遮罩,就设置transformLocation 为 BLEViewTransformLocationOriginal,返回到原始位置

-(void)didClickCoverButton{

self.transformLocation = BLEViewTransformLocationOriginal;

}



总结:主要思想就上面那么多,代码很简单,大家可以用苹果自带的侧滑手势,用一下更加简洁。
上一篇下一篇

猜你喜欢

热点阅读