gpt4 book ai didi

ios - UIScrollView 内部的 UIScrollView

转载 作者:IT王子 更新时间:2023-10-29 07:52:52 53 4
gpt4 key购买 nike

我有一个 UIScrollView 和另一个 UIScrollView 。它们都水平滚动并且具有 pagingEnabled = YES。假设我开始滚动内部 ScrollView 并到达最右边界。如果我继续在其中滚动,则外部 scrollView 开始移动。我需要避免这种情况。内部 View 应以橡皮筋效果跳跃,外部 View 应保持原位。

希望它很清楚,但这里有一个草图: enter image description here

我试过像这样设置 outerView.scrollEnabled = NO;:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
outerView.scrollEnabled = NO;
}

,如果只在 innerView 中滚动,它完全符合我的需要。 OuterView 不再滚动。但是如果我想再次滚动 outerView,我必须在某个地方将 scrollEnabled 设置回 YES。我试过在这里这样做:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
outerView.scrollEnabled = YES;
}

,但我遇到了同样的问题:在到达 innerView 的最右边界后,outerView 滚动而不是 innerView 以橡皮筋效果跳跃。

有什么解决问题的建议吗?

最佳答案

更新

此解决方案始终有效:

@implementation InnerScrollViewController <UIScrollViewDelegate, UIGestureRecognizerDelegate>

- (void)viewDidLoad
{
UISwipeGestureRecognizer* swipeGesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)] autorelease];
swipeGesture.delegate = self;
[self.view addGestureRecognizer:swipeGesture];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
_outerScrollView.scrollEnabled = NO;
return YES;
}

- (void)handleSwipe:(UIGestureRecognizer*)gestureRecognizer
{

}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
_outerScrollView.scrollEnabled = NO;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate)
{
_outerScrollView.scrollEnabled = YES;
}
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
_outerScrollView.scrollEnabled = YES;
}

@end

-------------------------------------------- --------------------------

旧答案:并不总是有效

我是这样解决问题的:

@implementation InnerView

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.delaysContentTouches = NO;
}
return self;
}

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
return NO;
}

据我了解,self.delaysContentTouches = NO; 使所有事件立即传递,并且 - (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view 阻止响应链传递这些事件。

关于ios - UIScrollView 内部的 UIScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15437515/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com