关于悬浮按钮其实就是 给按钮加了个拖动的属性 下面有个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];
}
}