Ios 不同视图控制器的UIScrollView通用
我必须有一个带有9个选项卡的选项卡栏,所以我添加了一个带有9个按钮的Srollview(MHScrollViewController),而不是选项卡栏。单击每个按钮后,我将viewController作为子视图添加到Srollview 在AppDelegate中,具有以下代码:Ios 不同视图控制器的UIScrollView通用,ios,uiscrollview,uinavigationcontroller,Ios,Uiscrollview,Uinavigationcontroller,我必须有一个带有9个选项卡的选项卡栏,所以我添加了一个带有9个按钮的Srollview(MHScrollViewController),而不是选项卡栏。单击每个按钮后,我将viewController作为子视图添加到Srollview 在AppDelegate中,具有以下代码: MHScrollViewController *scrollViewController = [[MHScrollViewController alloc] initWithNibName:@"MHScrollView"
MHScrollViewController *scrollViewController = [[MHScrollViewController alloc] initWithNibName:@"MHScrollView" bundle:nil];
scrollViewController.managedObjectContext = [self managedObjectContext];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:scrollViewController];
self.window.rootViewController = self.navigationController;
现在,对于一个选项卡(按钮),我已经将MHBikesViewController作为子视图添加到MHScrollViewController中。在MHScrollViewController中,我这样做
bikesViewController = [[MHBikesViewController alloc] initWithNibName:@"MHBikesView" bundle:nil];
bikesViewController.managedObjectContext = self.managedObjectContext;
bikesViewController.view.frame = baseViewiPhone.frame;
CGRect theFrame = bikesViewController.view.frame;
theFrame.origin.y = 0;
bikesViewController.view.frame = theFrame;
bikesViewController.navigationController = self.navigationController;
[baseViewiPhone addSubview:bikesViewController.view];
现在,我在MHBikesViewController页面上有两个按钮。单击后,我想在MHBikesViewController上推送一个新的viewcontroller。我可以按,但scrollView会隐藏在此viewcontroller下。UINavigationController将使用新按下的控制器覆盖其所有内容,因此您需要使用navigationcontroller之外的按钮来获取scrollView UINavigationController将使用新按下的控制器覆盖其所有内容,因此您需要使用navigationcontroller之外的按钮进行滚动查看 在设计UI时,请注意UIViewController的父/子关系和责任 控制器包含主UIView及其所有子视图。 将此viewController的视图添加到更复杂的视图层次结构中时,此控制器应该是控制此“容器”UI的viewController的子级 问问自己:你的遏制模式是什么 占据屏幕其余部分的9个选项卡和一些相关内容 然后在您的例子中,
MHScrollViewController
是主视图,它包含可滚动的选项卡和当前的viewController主视图。它不应该是UINavigationController
(它本身可以是持有您的MHBikesViewController
的父级“内容”)
在您的情况下,父容器->子容器:
MHScrollViewController
->UINavigationController
->MHBikesViewController
添加和删除子viewController由父级负责
//(somewhere in MHScrollViewController.m or .h )
@property (nonatomic, strong) UIViewController *newContentController;
@property (nonatomic, weak) UIScrollView *tabsScrollView;
// method for pushing any 'tab' controller
// might be your UINavigationController
- (void)displayTabController:(UIViewController *)vc
{
// remove previous controller
if (self.contentController) {
[self.contentController.view removeFromSuperview];
[self.contentController removeFromParentViewController];
}
//push the new controller, maintaining child/parent relationship
self.contentController = newContentController;
[self.view addSubview:contentController.view];
[self.contentController didMoveToParentViewController:self];
// set frame of contentController so that it stays above scrollView
self.contentController.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - self.tabsScrollView.bounds.size.height)
}
在设计UI时,请注意UIViewController的父/子关系和责任 控制器包含主UIView及其所有子视图。 将此viewController的视图添加到更复杂的视图层次结构中时,此控制器应该是控制此“容器”UI的viewController的子级 问问自己:你的遏制模式是什么 占据屏幕其余部分的9个选项卡和一些相关内容 然后在您的例子中,
MHScrollViewController
是主视图,它包含可滚动的选项卡和当前的viewController主视图。它不应该是UINavigationController
(它本身可以是持有您的MHBikesViewController
的父级“内容”)
在您的情况下,父容器->子容器:
MHScrollViewController
->UINavigationController
->MHBikesViewController
添加和删除子viewController由父级负责
//(somewhere in MHScrollViewController.m or .h )
@property (nonatomic, strong) UIViewController *newContentController;
@property (nonatomic, weak) UIScrollView *tabsScrollView;
// method for pushing any 'tab' controller
// might be your UINavigationController
- (void)displayTabController:(UIViewController *)vc
{
// remove previous controller
if (self.contentController) {
[self.contentController.view removeFromSuperview];
[self.contentController removeFromParentViewController];
}
//push the new controller, maintaining child/parent relationship
self.contentController = newContentController;
[self.view addSubview:contentController.view];
[self.contentController didMoveToParentViewController:self];
// set frame of contentController so that it stays above scrollView
self.contentController.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - self.tabsScrollView.bounds.size.height)
}
您可以用标准方式创建一个带有9个选项卡的选项卡栏。它将自动创建一个“更多”选项卡。它可能没有你想要的那么光滑。你可以有一个带有9个标签的标签栏。它将自动创建一个“更多”选项卡。它可能没有你想要的那么光滑