我有一个视图,我目前隐藏在屏幕底部。现在我希望能够通过 y 轴垂直滚动来移动视图。但我不希望它超过视图的全高度(即:我不想在底部看到空白)。我写了这段代码:
- (IBAction)panHighlightReadingVC:(UIPanGestureRecognizer *)recognizer
{
CGPoint translation = [recognizer translationInView:self.view];
CGPoint newCenter = CGPointMake(self.view.bounds.size.width / 2,
roundf(recognizer.view.center.y + translation.y));
CGFloat velocityY = [recognizer velocityInView:self.view].y;
if ((recognizer.view.frameY > self.view.frameHeight - recognizer.view.frameHeight || velocityY > 0)) {
recognizer.view.center = newCenter;
[recognizer setTranslation:CGPointZero inView:self.view];
}
}
这种工作,如果我慢慢滚动的话。如果我滚动得非常快,那么视图的 frameY 有可能小于 `superView.frameHeight - Recognizer.view.frameHeight。我该如何解决?