一:前言
可以随意拖动的UITextField
二:简要步骤
<0> 新建CustomFlowTextField继承于UITextField
<1>在.m文件写下touchesMoved的方法
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
UITouch * touch = [touches anyObject];
//本次触摸点
CGPoint current = [touch locationInView:self];
//上次触摸点
CGPoint previous = [touch previousLocationInView:self];
//未移动的中心点
CGPoint center = self.center;
//移动之后的中心点(未移动的点+本次触摸点-上次触摸点)
center.x += current.x - previous.x;
center.y += current.y - previous.y;
//更新位置
self.center = center;
}
<2>欢迎各位大牛补充指正
网友评论