我正在嘗試製作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