UIScrollView 将视图推送到 UINavigationController 后停止工作 [英] UIScrollView Stop working after push view to UINavigationController

查看:21
本文介绍了UIScrollView 将视图推送到 UINavigationController 后停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The scrollview in my main page stop working if I push something to the navigation controller and then pop back to the main page. It works normally if I reopen the application without pushing anything to the navigation controller yet. The scrollview is a horizontal scrollview which extends beyond the frame. I use it to scroll through buttons like when you switch application in iOS (iOS multitasking).

这是我推送新vc的代码

This is the code where I push a new 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];

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

when that view controller is popped and navigation controller move back to the main page I hide the 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.

checking isScrollEnable return true.

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

I tried pushing a normal modal view and the same problem occur.

推荐答案

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

Problem solved by creating the UIScrollview and the button inside it programmatically. Not sure what I did wrong with storyboard, but it's a pain.

这篇关于UIScrollView 将视图推送到 UINavigationController 后停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆