我正在构建一个 iPad 应用程序,我需要允许使用两个视图之间提供的分隔视图来调整视图大小。分隔视图只是两个半屏内容视图之间的 20 像素高度视图 - 请参阅附加图像。
当用户向上或向下滚动此分隔视图时,两个内容视图都会相应地更改其大小。我已经UIView
使用委托扩展并实现了这一点touchMoved
,如下委托中给出的代码touchesMoved
。它工作正常。唯一缺少的TouchMoved
是您不能直接将分隔视图滑动到顶部或底部。你必须一直拖到顶部或底部!
为了支持轻弹我尝试过的视图,UIPanGestureRecognizer
但我没有看到平滑的拖动。设置父级的拆分位置会调整两个内容视图的大小,如代码所示。当我处理状态中的拆分位置更改时UIGestureRecognizerStateChanged
,只需触摸分隔线视图即可将其轻弹到顶部或底部。处理拆分位置的变化是UIGestureRecognizerStateEnded
一样的,但我没有看到内容视图通过dividerview滚动调整大小!
有人能告诉我如何通过调整内容视图(如touchMoved
)和轻弹视图来实现分隔视图的平滑滚动吗?任何替代方法也可以。谢谢。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if (touch) {
CGPoint lastPt = [touch previousLocationInView:self];
CGPoint pt = [touch locationInView:self];
float offset = pt.y - lastPt.y;
self.parentViewController.splitPosition = self.parentViewController.splitPosition + offset;
}
}
- (void)handlePan:(UIPanGestureRecognizer*)recognizer {
CGPoint translation = [recognizer translationInView:recognizer.view];
CGPoint velocity = [recognizer velocityInView:recognizer.view];
if (recognizer.state == UIGestureRecognizerStateBegan) {
} else if (recognizer.state == UIGestureRecognizerStateChanged) {
// If I change split position here, I don't see smooth scrolling dividerview...it directly jumps to the top or bottom!
self.parentViewController.splitPosition = self.parentViewController.splitPosition + translation.y;
} else if (recognizer.state == UIGestureRecognizerStateEnded) {
// If I change split position here, the same thing happens at end and I don't see my divider view moving with my scrolling and resizing my views.
self.parentViewController.splitPosition = self.parentViewController.splitPosition + translation.y;
}
}
初始画面
通过向底部滚动分隔视图来增加顶视图的大小。
顶视图完全隐藏在这里,但我必须将分隔视图一直滚动到顶部。我想轻弹分隔视图,使其直接从任何位置到顶部