【问题标题】:All UIScrollView descendants in my app have stopped responding to scrolling我的应用程序中的所有 UIScrollView 后代都停止响应滚动
【发布时间】:2012-08-06 10:33:51
【问题描述】:

我不知道我做了什么,但我正在实现 UIViewController Containment,突然间 UIKit UIScrollView 子类停止响应滚动,即使我绕过了所有自定义应用程序代码。比如这个标准的设置代码……

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

UIViewController *vc = [[UIViewController alloc] init];
vc.view = [[UIView alloc] initWithFrame:self.window.frame];

UIScrollView *sv = [[UIScrollView alloc] initWithFrame:vc.view.frame];
sv.contentSize = CGSizeMake(400, 3000);
[vc.view addSubview:sv];

在一个全新的 Xcode 项目中,scrollView 滚动,但在我现有的项目中,滚动没有效果,滚动条也没有出现。两个项目中的 AppDelegate 代码是相同的,我唯一的#import 是 UIKit。

换句话说,我的应用程序中从 UIScrollView 继承的所有类突然表现得好像它们的 scrollEnabled 属性设置为 NO,我无法更改它。

【问题讨论】:

    标签: objective-c ios xcode uitableview uikit


    【解决方案1】:

    它可能是界面生成器中滚动视图上的“启用滚动”属性。

    【讨论】:

      【解决方案2】:
        // define the area that is initially visible
        scrollViewCustom.frame = CGRectMake(0, 5, 354, 500);
      
        // then define how much a user can scroll it
        [scrollViewCustom setContentSize:CGSizeMake(354, 960)];
      

      另外,清除滚动视图的背景颜色以显示文本。

         scrollViewCustom.backgroundColor = [UIColor clearColor];
      

      【讨论】:

      • 此代码实际上与我在示例中提供的代码相同。我的背景颜色没有问题,问题在于滚动。
      【解决方案3】:

      你可以像这样简单地创建。

      scrollView=[[UIScrollView alloc]init]WithFrame:CGRectMake(0,0 ,320,480)];
      [scrollView setScrollEnabled:YES];
      [scrollView setContentSize:CGSizeMake(320, 600)];
      scrollView.backgroundColor = [UIColor clearColor];
      

      【讨论】:

      • scrollEnabled 默认为 YES。这个问题会影响到我的应用程序中从 UIScrollView 继承的每个类(所有 UITableViews、UITextViews 等)。
      • 你的scrollingView运行良好,你的问题是什么?
      • 问题是我的应用程序中所有继承自 UIScrollView (UITableViews, UITextViews) 的类都突然停止响应滚动。 IE。他们都表现得好像 scrollEnabled 是 NO,即使我已将其设置为 YES。
      • tableView 和 textView 是控件而不是类。当在 tableView 上滚动时,scrollView 不会滚动,而在 textView 上滚动 scrollView 不会滚动,在这些控件之外,您尝试滚动只会滚动 scrollView。
      【解决方案4】:

      AFAIK 这是由于糟糕的第三方代码使用了UIPanGestureRecognizers 而没有实现gestureRecognizerShouldBegin:,从而覆盖了正常的滚动行为。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多