【问题标题】:UIScrollView Stop working after push view to UINavigationControllerUIScrollView 将视图推送到 UINavigationController 后停止工作
【发布时间】:2013-05-14 09:04:23
【问题描述】:

如果我将某些内容推送到导航控制器然后弹回主页,则主页中的滚动视图将停止工作。如果我重新打开应用程序而不向导航控制器推送任何内容,它可以正常工作。滚动视图是延伸到框架之外的水平滚动视图。我用它来滚动按钮,就像在 iOS 中切换应用程序时一样(iOS 多任务处理)。

这是我推送新 vc 的代码

    UIViewController *newVC = [[UIViewController alloc] init];    
    UILabel *label = [[UILabel alloc] initWithFrame:self.view.bounds];
    [label setTextAlignment:NSTextAlignmentCenter];
    label.text = [NSString stringWithFormat:@"promo %i detail view",[sender tag]];
    label.backgroundColor = [UIColor whiteColor];
    [newVC.view addSubview:label];

    [self.navigationController setNavigationBarHidden:NO animated:NO];
    [self.navigationController pushViewController:newVC animated:YES];

当视图控制器被弹出并且导航控制器移回主页时,我隐藏了导航栏。

    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
        if(viewController == self){
            [self.navigationController setNavigationBarHidden:YES];
            NSLog(@"%d", [self.scrollMenuBar isScrollEnabled]);
        }
    }

检查 isScrollEnable 是否返回 true。

我尝试推送一个普通的模态视图,但出现了同样的问题。

【问题讨论】:

  • 还要检查scrollView的contentsize,是否保持不变。?弹出后
  • 是的,它保持不变@Bonnie

标签: ios uiscrollview uinavigationcontroller


【解决方案1】:

如果您在 viewDidLayoutSubview 函数中调整滚动视图内容的大小,它将再次起作用。

- (void) viewDidLayoutSubviews {
    [self resizeScrollViewContent];
}

【讨论】:

    【解决方案2】:

    添加 [self.scrollbarMenu setScrollEnabled:YES]; 在主页面的 viewdidAppear 中

    添加

    [scroll setContentSize:CGSizeMake(width , height)];
    

    如果它不起作用 2种可能性

    1. 内存无效。
    2. 其他一些视图位于滚动视图上方

    【讨论】:

    • 在此处添加内容大小并重试
    • 还是不行,我检查了 pop 后 scrollEnable 和 contentSize 保持不变
    • 滚动视图中的按钮仍然可以点击。
    【解决方案3】:

    通过以编程方式创建 UIScrollview 和其中的按钮解决了问题。不知道我在情节提要上做错了什么,但这很痛苦。

    【讨论】:

    • 也许禁用自动布局也可以解决问题。
    猜你喜欢
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-31
    相关资源
    最近更新 更多