我正在尝试制作UIView/UIControl,用户可以拖动并显示文本框,然后向下拖动以隐藏它。然而,我还没有找到一种使这种“流动”的方法 - 它似乎总是在随机的地方停下来,并且不允许有更多的动作。目前我正在使用UIView作为视图的顶部,这里是当前的代码:CocoaTouch中的下拉菜单
- (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;
}
}
任何帮助将不胜感激!
感谢您的回复,Cory!我目前使用“if(translation.y <(self.frame.size.height - topView.frame.size.height)&& translation.y> 0)”来限制视图向上移动的距离。它第一次效果很好,但对于第二次,它只能根据过去的帧进行调整。有没有办法解决这个问题? – PF1 2010-10-31 02:46:27