最近做的项目,需要一个悬浮并可移动的按钮, 我就在网上搜了一个第三方的UIButton+NMCategory,
结果谁知道, 好多不需要移动的button,竟然失灵了, 只有在6s 6sPlus上失灵, 在iPhone5s 6 6Plus上都没有问题, 经过仔细检查原来是 把 self.highlighted = NO, 把所有button的高亮状态都取消掉了,当你按住button后再松手,就不会起作用了
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
self.highlighted = NO;
if (![objc_getAssociatedObject(self, DragEnableKey) boolValue]) {
return;
}
UITouch *touch = [touches anyObject];
CGPoint nowPoint = [touch locationInView:self];
float offsetX = nowPoint.x - beginPoint.x;
float offsetY = nowPoint.y - beginPoint.y;
self.center = CGPointMake(self.center.x + offsetX, self.center.y + offsetY);
}
果断弃之!