简体   繁体   English

如何在 UIScrollView 上添加 UIViewController 视图

[英]How to add a UIViewController view on UIScrollView

I have a small problem in loading the UIViewController on scroll view.我在滚动视图上加载 UIViewController 时遇到了一个小问题。

In my application, I am using 4 tab buttons at the bottom.在我的应用程序中,我在底部使用了 4 个选项卡按钮。 One of which contains a scroll view, as number of fields in that view are more.其中一个包含滚动视图,因为该视图中的字段数更多。 One of the field is for accepting the date from the user.该字段之一用于接受来自用户的日期。

When I am adding this Date Picker View(UIViewController) on UIViewController class, there is no problem in loading the Date Picker View, but when I am adding Date Picker View on UIScrollView there is problem.当我在 UIViewController 类上添加这个日期选择器视图(UIViewController)时,加载日期选择器视图没有问题,但是当我在 UIScrollView 上添加日期选择器视图时出现问题。 Application crashes when I am touching any button on Date Picker View.当我触摸日期选择器视图上的任何按钮时,应用程序崩溃。

Is there any problem in loading the UIViewController on UIScrollView ???.在 UIScrollView 上加载 UIViewController 有什么问题吗???。 What is the alternative if I want to accept the date form user on scroll view or how can I add the UIViewController on scroll view to accept the date from Date picker.如果我想在滚动视图上接受日期表单用户,或者如何在滚动视图上添加 UIViewController 以接受来自日期选择器的日期,有什么替代方法。

Thanks in Advance.提前致谢。 Regards, VIshal.问候,维沙尔。

Try this and see:试试这个,看看:

self.scrollView.frame = CGRect( <set frame> )

var vcView = UIView(frame: CGRect( <set frame> ))
addChildVC(vcView: vcView)

self.scrollView.addSubview(vcView)
self.scrollView.contentSize = CGSize( <set content size> )

Add child view Controller添加子视图控制器

func addChildVC(vcView: UIView){

let testVC = self.storyboard?.instantiateViewControllerWithIdentifier("testIdentifier") as! TestViewController
    testVC.view.frame = vcView.bounds
    vcView.addSubview(testVC.view)
    self.addChildViewController(testVC)
    testVC.didMoveToParentViewController(self)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM