【问题标题】:Swift popupView not working (2 didMoveToParentViewController view exist)Swift popupView 不起作用(存在 2 个 didMoveToParentViewController 视图)
【发布时间】:2016-08-23 12:02:47
【问题描述】:

我有一个用这个 tutorial 创建的 3 滑动 ViewController 所以,HomeViewController 是这 3 个视图的控制器。

代码是

Class HomeViewController //......
func prepareScrollView(){

let V1 : FirstViewController = FirstViewController(nibName: "FirstViewController", bundle: nil)

let V2 : SecondViewController = SecondViewController(nibName: "SecondViewController",bundle: nil)

let V3 : ThirdViewController = ThirdViewController(nibName: "ThirdViewController",bundle: nil)

self.addChildViewController(V1)
self.scrollView.addSubview(V1.view)
V1.didMoveToParentViewController(self)

self.addChildViewController(V2)
self.scrollView.addSubview(V2.view)
V2.didMoveToParentViewController(self)

self.addChildViewController(V3)
self.scrollView.addSubview(V3.view)
V3.didMoveToParentViewController(self)

var V2Frame : CGRect = V1.view.frame
V2Frame.origin.x = self.view.frame.width
V2.view.frame = V2Frame


var V3Frame : CGRect = V3.view.frame
V3Frame.origin.x = 2 * self.view.frame.width
V3.view.frame = V3Frame

self.scrollView.contentSize = CGSizeMake(self.view.frame.width * 3, self.view.frame.size.height)
self.scrollView.contentOffset = CGPoint(x: self.view.frame.width,y : self.view.frame.height)

 }

在 SecondViewController 中,我创建了一个按钮来显示弹出视图,但它不起作用。 我认为原因是存在 2 个didMoveToParentViewController

第二个VC:

PopButton.addTarget(self, action: #selector(settingUpView), forControlEvents: .TouchUpInside)

func settingUpView(){

print("touched")

let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("PopUpView") as! PoPViewController
self.addChildViewController(popOverVC)
popOverVC.view.frame = self.view.frame
self.view.addSubview(popOverVC.view)
popOverVC.didMoveToParentViewController(self)  
}

当我点击按钮时,它只显示print,但没有弹出任何内容,请问我该如何解决这个问题?

【问题讨论】:

    标签: ios swift


    【解决方案1】:
    popOverVC.view.frame = self.view.frame
    

    上面的代码不对。 self.view.frame.origin 不是 CGPointZero。

    【讨论】:

    • 对于批评,使用 cmets。不要将其发布为答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多