我正在尝试制作一个 UIView/UIControl,人们可以向上拖动并显示一个文本框,然后向下拖动以隐藏它。但是,我还没有找到一种方法来使这种“流动”——它似乎总是停在随机的地方,并且不允许更多的移动。目前我正在使用 UIView 作为视图的顶部,这是当前代码:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch view] == topMenuView) {
CGPoint location = [touch locationInView:self.superview];
CGPoint locationInsideBox = [touch locationInView:self];
CGPoint newLocation = location;
newLocation.x = self.center.x;
newLocation.y = newLocation.y + (self.frame.size.height - locationInsideBox.y) / 2;
if ((self.superview.frame.size.height - newLocation.y) < (self.frame.size.height / 2) && (self.superview.frame.size.height - newLocation.y) > -32)
{
self.center = newLocation;
}
return;
}
}
任何帮助将非常感激!