【发布时间】:2011-04-21 08:57:24
【问题描述】:
我正在尝试制作一个 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;
}
}
任何帮助将不胜感激!
【问题讨论】:
标签: iphone cocoa-touch uiview uikit uicontrol