优秀比不过别人,那么努力呢?

iOS 悬浮按钮

关于悬浮按钮其实就是 给按钮加了个拖动的属性   下面有个bug就是  当你的页面有变化时  按钮会归位  比如 tableview 滑动

按钮添加手势

 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pantoBtn:)];

        [btn addGestureRecognizer:pan];

 

#pragma mark  按钮拖动事件

-(void)pantoBtn:(UIPanGestureRecognizer *)pan

{

    

    CGPoint point = [pan locationInView:self.view];

    

    MapBtn.center = point;

    

    if (([(UIPanGestureRecognizer *)pan state] == UIGestureRecognizerStateEnded )||

        ([(UIPanGestureRecognizer *)pan state] == UIGestureRecognizerStateCancelled

        )) {

            CGFloat x = pan.view.center.x;

            CGFloat y = pan.view.center.y;

            

            if (x > ViewWith / 2.0) {

                x = ViewWith - 30;

            }else {

            

                x = 30;

            }

            

            

            if (y > ViewHight - 50) {

                y = ViewHight - 70;

            }else if (y < 66)

            {

                y = 96;

            }

            

            CGFloat velocityX = (0.2 * [pan velocityInView:self.view].x);

            

            [UIView beginAnimations:nil context:NULL];

            

            [UIView setAnimationDuration:ABS(velocityX * 0.00002 + 0.2)];

            

            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

           

            pan.view.center = CGPointMake(x, y);

            NSLog(@"%@",pan.view)

            [UIView commitAnimations];

            

      

    }

   

    

}

 

posted @ 2016-06-24 14:18  一只卑微的蚂蚁  阅读(941)  评论(0编辑  收藏  举报