我有PopUpViewControllerSwift
我想一次又一次地弹出,直到alreadyMatched
索引达到零。这就是我执行弹出窗口的方式,代码:
var alreadyMatched = [0,1,2]
class QuestionsGame: UIViewController {
var popUpViewController = PopUpViewControllerSwift()
override func viewDidLoad() {
super.viewDidLoad()
matched()
}
func matched() {
var a = alreadyMatched.count
if a > 0 {
self.view.addSubview(self.popUpViewController.view)
self.addChildViewController(self.popUpViewController)
self.popUpViewController.setValues(UIImage(named: "hot.png"), messageText: "You have matched!!", congratsText: "Snap!")
self.popUpViewController.didMoveToParentViewController(self)
alreadyMatched.removeLast()
}
}
}
PopUpViewControllerSwift
代码是:
@objc class PopUpViewControllerSwift : UIViewController {
var popUpUserImage: UIImageView!
var messageLabel: UILabel!
var popUpView: UIView!
var congratsLabel: UILabel!
var matchedOrNot = 2
var matchedUser : PFUser!
override func viewDidLoad() {
super.viewDidLoad()
}
func setValues(image : UIImage!, messageText : String, congratsText : String) {
self.popUpUserImage!.image = image
self.messageLabel!.text = messageText
self.congratsLabel.text = congratsText
}
func showAnimate()
{
self.view.transform = CGAffineTransformMakeScale(1.3, 1.3)
self.view.alpha = 0.0;
UIView.animateWithDuration(0.25, animations: {
self.view.alpha = 1.0
self.view.transform = CGAffineTransformMakeScale(1.0, 1.0)
});
}
func removeAnimate()
{
UIView.animateWithDuration(0.25, animations: {
self.view.transform = CGAffineTransformMakeScale(1.3, 1.3)
self.view.alpha = 0.0;
}, completion:{(finished : Bool) in
if (finished)
{
self.view.removeFromSuperview()
let sb = UIStoryboard(name: "Main", bundle: nil)
let questionsVC = sb.instantiateViewControllerWithIdentifier("Questions") as! QuestionsGame
questionsVC.timer()
}
})
}
}
由于某种原因,这只会弹出一次,不会重复?我确定这与 ParentViewController 有关吗?