UIPanGestureRecognizer给视图添加平移手势(有4边境的平移)

来源:互联网 发布:mac excel换行快捷键 编辑:程序博客网 时间:2024/05/01 18:48

-(void)panViewMovie:(UIPanGestureRecognizer *)pan{

    

    CGPoint transP = [pantranslationInView:self.playLView];

    CGFloat offsetX = transP.x;

    CGFloat offsetY = transP.y;

    

    self.playLView.frame =CGRectMake(self.playLView.frame.origin.x+offsetX,self.playLView.frame.origin.y+offsetY,self.playLView.frame.size.width,self.playLView.frame.size.height);

    [pan setTranslation:CGPointZeroinView:self.playLView];

    

    CGFloat minX =0;

    CGFloat maxX =SCREEN_WIDTH-self.playLView.frame.size.width;

    CGFloat minY =0;

    CGFloat maxY =SCREEN_HEIGHT-self.playLView.frame.size.height;

    CGFloat curX,curY;

    if (pan.state ==UIGestureRecognizerStateEnded) {

        //x

        if (self.playLView.frame.origin.x >=minX&& self.playLView.frame.origin.x <=maxX) {

            curX = self.playLView.frame.origin.x+offsetX;

        }elseif (self.playLView.frame.origin.x <minX){

            curX = minX;

        }else {

            curX = maxX;

        }

        //y

        if (self.playLView.frame.origin.y >=minY&& self.playLView.frame.origin.y <=maxY) {

            curY = self.playLView.frame.origin.y+offsetY;

        }elseif (self.playLView.frame.origin.y <minY){

            curY = minY;

        }else {

            curY = maxY;

        }

        

        [UIViewanimateWithDuration:0.25animations:^{

            self.playLView.frame =CGRectMake(curX, curY,self.playLView.frame.size.width,self.playLView.frame.size.height);

        } completion:^(BOOL finished) {

        }];

    }

    

}

0 0
原创粉丝点击