view触摸移动

来源:互联网 发布:gmt时间 Linux 转换 编辑:程序博客网 时间:2024/05/29 02:31
/**
 *  触摸ing(手指在view上面挪来挪去)
 */
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    
    // 当前触摸点
    CGPoint current = [touch locationInView:self];
    // 上一个触摸点
    CGPoint previous = [touch previousLocationInView:self];
    
    // 修改当前view的位置(中点)
    CGPoint center = self.center;
    center.x += current.x - previous.x;
    center.y += current.y - previous.y;
    self.center = center;

}

实现view跟随触摸移动


补充:

判断一个点是否在一个区域内:

if (CGRectContainsPoint(btn.frame, point))




0 0
原创粉丝点击