【问题标题】:UIScrollView and UINavigationController not working with iOS 4UIScrollView 和 UINavigationController 不适用于 iOS 4
【发布时间】:2012-06-04 15:39:08
【问题描述】:

我在使用 UIScrollView 和 UINavigationController(s) 以及 iOS 4 时遇到问题。以下代码适用于 iOS 5:

 ////////////////////////////////////////////////////////////////////////////////////
 /* Scroll View */ 
 ////////////////////////////////////////////////////////////////////////////////////
 mScrollView = [[UIScrollView alloc]   initWithFrame:CGRectMake(0, 88, 1024, 668)];
 mScrollView.contentSize = CGSizeMake(1850, 668);

 ////////////////////////////////////////////////////////////////////////////////////
 // First View 
 ////////////////////////////////////////////////////////////////////////////////////
 UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:           @"view_bg.png"]];
 imgView.frame= CGRectMake(10, 50, 350, 510);
 [mScrollView addSubview:imgView];
 [imgView release];

 mFirstView = [[[FirstView alloc]  init] autorelease];
 UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mFirstView]; 
 navigationController.navigationBar.tintColor = [UIColor colorWithRed:79.0/255 green:143.0/255 blue:0.0/255 alpha:1];
 navigationController.view.frame = CGRectMake(25, 65, 320, 480);   
 [mScrollView addSubview:navigationController.view];

 ////////////////////////////////////////////////////////////////////////////////////
 // Second View
 ////////////////////////////////////////////////////////////////////////////////////
 UIImageView *imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"view_bg.png"]];
 imgView2.frame= CGRectMake(380, 50, 350, 510);
 [mScrollView addSubview:imgView2];
 [imgView2 release];

 mSecondView = [[[SecondView alloc]  init] autorelease];
 UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:mSecondView]; 
 navigationController2.navigationBar.tintColor = [UIColor colorWithRed:79.0/255     green:143.0/255 blue:0.0/255 alpha:1];
 navigationController2.view.frame = CGRectMake(395, 65, 320, 480);
[mScrollView addSubview:navigationController2.view];

// finally add the scroll view to the parent view
[self.view addSubview:mScrollView];

我所做的只是添加一个带有 2 个 NavigationControllers(带有分配的根视图控制器)的 ScrollView 来执行视图。但是在 iOS 4 中使用此代码不会显示添加的 ViewController 的正确大小。 ViewController 是整个 iPad 屏幕的大小!!!!!!!

正如我已经说过的,它适用于 iOS 5!即使我更改了手动添加的视图的大小,它也不起作用,添加的视图总是填满整个 iPad 屏幕!!有什么想法可以解决这个问题吗?

提前谢谢你!

【问题讨论】:

    标签: ios ios5 ios4 uinavigationcontroller uiscrollview


    【解决方案1】:

    在您的代码中,您有以下内容

    //first view you add mfirstview.view
    [mScrollView addSubview:mFirstView.view];
    
    //second view you add navigationController2.view
    [mScrollView addSubview: navigationController2.view];
    

    所以我猜你必须更改第一个视图代码才能执行以下操作

    [mScrollView addSubview: navigationController.view];
    

    【讨论】:

    • 哦对不起..这是一个错字!!我从我的代码中更改了原始类名......我编辑了我上面的帖子!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    相关资源
    最近更新 更多