UIScrollView在推送视图到UINavigationController后停止工作

时间:2013-05-14 09:04:23

标签: ios uiscrollview uinavigationcontroller

如果我将某些内容推送到导航控制器然后弹回主页面,我主页面中的滚动视图将停止工作。如果我重新打开应用程序而不向导航控制器推送任何东西,它会正常工作。 scrollview是一个水平滚动视图,它超出了框架。我用它来滚动按钮,就像你在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];

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

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

检查isScrollEnable返回true。

我尝试推动普通的模态视图,同样的问题也出现了。

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

添加

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

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

  1. 内存无效。
  2. 其他一些视图位于scrollview
  3. 之上

答案 2 :(得分:0)

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