インデックスがゼロに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()
}
})
}
}
なんらかの理由で、これは 1 回だけ表示され、繰り返し表示されませんか? 私はそれがParentViewControllerと関係があると確信していますか?