UIScrollView和UINavigationController不能与iOS 4一起使用

时间:2012-06-04 15:39:08

标签: ios ios5 ios4 uinavigationcontroller uiscrollview

我遇到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中使用此代码并未显示添加的ViewControllers的正确大小。 ViewControllers是整个iPad屏幕的大小!!!!!

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

提前谢谢!

1 个答案:

答案 0 :(得分:0)

在您的代码中

,您有以下

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

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

所以我想你必须改变第一个视图代码来执行以下操作

[mScrollView addSubview: navigationController.view];