UIScrollView with multiple UIViewControllers

送分小仙女□ 提交于 2019-12-21 02:57:15

问题


i have one scrollview and 4 UIviewcontrollers with xib files now i want to add 4 viewcontrollers to scrollview

and also the scroll is enabled for four viewcontrollers

any one know this plz answer this problem


回答1:


Just add them. What's the problem?

// this loads a view controller from a nib
controller = [[UIViewController alloc] initWithNibName:@"YourNibsName" bundle:nil];

// this adds the viewcontroller's view to the scrollview
[scrollView addSubview:controller.view];

// place the subview somewhere in the scrollview
CGRect frame = controller.view.frame;
frame.origin.x = 600;
controller.view.frame = frame;

// don't forget to release the viewcontroller somewhere in your dealloc
[controller release];

Do this for all your four controllers.




回答2:


yes, you can just add the views of the viewcontrollers to your scrolling view, but remember that you are rolling your own equivalent to a UITabBarController or UINavigationController and so you have some responsibilities:

When you alloc init your vc from a nib the vc will get its viewDidLoad method called.

But when you put the vc.view into your scrollview YOU need to call [vc viewDidAppear:YES] (and also call viewWillAppear just before if your vc uses it).

Be careful with things like presenting modal view controllers from your vc as this may not work as you expect.

Peter




回答3:


I realize that it's quite an old question. But now you can use UIPageViewController.



来源:https://stackoverflow.com/questions/4977283/uiscrollview-with-multiple-uiviewcontrollers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!