2012-04-02 125 views
7

我有分页一个UIScrollView像下面启用:UIScrollView的内容不允许用户交互

container = [[UIScrollView alloc] initWithFrame:kScrollViewFrame]; 
[container setDelegate:self]; 
[container setShowsHorizontalScrollIndicator:YES]; 
[container setShowsVerticalScrollIndicator:NO]; 
[container setClipsToBounds:YES]; 
[container setPagingEnabled:YES]; 
[container setDecelerationRate:UIScrollViewDecelerationRateFast]; 
[container setBounces:NO]; 
[container setUserInteractionEnabled:NO]; 
[container setCanCancelContentTouches:NO]; 
[container setDelaysContentTouches:NO]; 

到的UIScrollView,我添加几个UIWebViews中,并设置启用它们之间的相互作用是像这样。

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 

     self.frame = frame; 
     self.userInteractionEnabled = YES; 
    } 
    return self; 
} 

这打破了分页和所有接触UIScrollView。如果我将用户交互设置为NO,页面可以工作,但我无法在UIWebView中突出显示文本。我试着像下面这样继承UIScrollView,但情况相同。任何想法?

- (id)initWithFrame:(CGRect)frame 
{ 
    NSLog(@"init"); 
    return [super initWithFrame:frame]; 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    NSLog(@"touchesBegan"); 

    [[self nextResponder] touchesBegan:touches withEvent:event]; 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    NSLog(@"touchesMoved"); 

    [[self nextResponder] touchesMoved:touches withEvent:event]; 
} 

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    NSLog(@"touchesEnded"); 
    [[self nextResponder] touchesEnded:touches withEvent:event]; 
} 
+0

它是什么你试图实现,你需要滚动视图滚动,Web视图滚动,分页,选择?请更具体一些。 – 2012-04-04 15:10:03

+0

我需要滚动视图页面和用户能够选择WebVies上的文本(这是滚动视图的子视图)Webview不需要滚动,只需能够选择其文本。 – 2012-04-04 15:37:14

+0

我编辑了我的答案以反映您的要求,它似乎对我有用。 – 2012-04-04 15:49:27

回答

10

禁用容器上的用户交互可以有效地在子视图上禁用它。您应该启用它,导致触摸事件向下传播到视图层次结构中;

[container setUserInteractionEnabled:YES]; 

如果你想在一个UIWebView禁用滚动刚进去的UIScrollView

yourWebView.scrollView.scrollEnabled = NO; 

我已经在我的设备上测试了这一点,我既可以“翻阅”的的UIScrollView和选择文本UIWebView的。

编辑:

我得到了这个工作!你必须允许触摸取消,以及:

[container setCanCancelContentTouches:YES]; 
+0

我已经尝试过这一点,它打破了scrollview子项的webviews上的用户交互。 – 2012-04-04 15:03:31

+0

我试过这个,我不能再滚动,即使thisc的uiscrollview的内容大小是10,000px,框架设置为屏幕宽度/高度(768 x 1024)编辑:实际上,如果我按住几秒钟,尝试刷卡。页面非常困难。你遇到这个问题吗? – 2012-04-04 16:51:53

+0

使用滑动识别器并自行为分页动画。 – 2012-04-04 18:16:36