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];

            

      

    }

   

    

}

 

转载于:https://www.cnblogs.com/Yangboskt/p/5614063.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值