У меня есть всплывающее окно просмотра в раскадровке.У меня есть кнопка отклонения, чтобы удалить всплывающее окно с видом.Но я также хочу проверить, был ли popOver уже запущен / показан пользователю.
Я вынужден использовать userDefaults в AppDelegate?У меня может не быть разрешения на изменение AppDelegate в реальном производственном приложении, с которым мне нужно это сделать.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var popOne: UIButton!
@IBOutlet weak var popTwo: UIButton!
// Using the popOver UIView NOT as a specialized UIView Class
@IBOutlet var PopOver: UIView!
@IBOutlet weak var dismissButton: UIButton!
@IBOutlet weak var popOverLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
PopOver.layer.cornerRadius = 10
}
func checkStatus() {
// check if the popOver view has already been presented
// ONLY present popOver is user hasn't seen it yet.
// if userStatusType == .complete
// run confetti popOver
// else if != .complete
// run the non-confetti overlay
}
// popOver One Action
@IBAction func popOneAction(_ sender: Any) {
// dismiss buttons enabled
popOne.isEnabled = false
popOne.backgroundColor = .green
popTwo.isEnabled = false
// present the popover
self.view.addSubview(PopOver)
// set the confetti to load only in popOver View
PopOver.clipsToBounds = true
PopOver.startConfetti()
// set the popOver to center view
PopOver.center = view.center
// modify popOver UI elements
popOverLabel.textColor = .green
popOverLabel.text = "GREEN and POP ONE. Notice Buttons in Background are now dismissed. So Press the popOver Button to remove the popOver and return to main VC."
// create a layer over the background VC
// Set the Overlay Color to a light gray
// Set the alpha / opacity to under 50% to keep the main UI still visible.
self.view.backgroundColor = .gray
self.view.alpha = 0.3
}
// popOver Two Action
@IBAction func popTwoAction(_ sender: Any) {
popOne.isEnabled = false
popTwo.isEnabled = false
PopOver.center = view.center
self.view.addSubview(PopOver)
popOverLabel.textColor = .cyan
popOverLabel.text = "YOU DID NOT COMPLETE CHALLENGES THIS MONTH. TRY AGAIN FOR NEXT MONTHS CHALLENGES"
}
@IBAction func dismissAction(_ sender: Any) {
popOne.isEnabled = true
popTwo.isEnabled = true
popOne.backgroundColor = #colorLiteral(red: 0, green: 0.3285208941, blue: 0.5748849511, alpha: 1)
popOverLabel.text = ""
// Dismiss the popOver
self.PopOver.removeFromSuperview()
// Rest the main VC UI
self.view.backgroundColor = .white
self.view.alpha = 1
}
}
Это всего лишь тестовый код.Так что просто опробую идею.