事件使用showInView崩溃了应用程序

时间:2015-05-18 09:34:14

标签: ios uiview uiviewcontroller

我刚刚创建了一个带有视图控制器和XIB文件的自定义弹出窗口。这个PopUp有一个关闭按钮,当它与self.presentViewController(popUp, animated: true, completion: nil)一起显示时工作正常,但是当我按下关闭按钮时用popUp.showInView(self.view, animated: true)调用它时访问不正确它会崩溃。

class PopUp: UIViewController {

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}

convenience init(){
    self.init(nibName: "PopUp", bundle: nil)
}
required init(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

func showInView(aView: UIView!, animated: Bool)
{
    self.view.frame = aView.frame
    aView.addSubview(self.view)
    if animated
    {
        self.showAnimate()
    }
}

func showAnimate()
{
    self.view.transform = CGAffineTransformMakeScale(1.3, 1.3);
    self.view.alpha = 0;
    UIView.animateWithDuration(0.25, animations: { () -> Void in
        self.view.alpha = 1
        self.view.transform = CGAffineTransformMakeScale(1, 1)
    })
}


func removeAnimate()
{
    UIView.animateWithDuration(0.25, animations: { () -> Void in
        self.view.transform = CGAffineTransformMakeScale(1.3, 1.3)
        self.view.alpha = 0.0
        }) { (finished) -> Void in
            if (finished) {
                self.view.removeFromSuperview()
            }       
    }
}

@IBAction func closePopup(sender: UIButton) {
    println("Closing")
    self.removeAnimate()
}

}

0 个答案:

没有答案