PopupEventPlayer

class PopupEventPlayer : UIView

Handles the entire popup lifecycle. Owns all popup views, media, and interactions.

Example retrieving a model from the Popups dataset:

// get the correct model
let scenarioID = 5
let popupID = 1
guard let model: PopupEvent = PopupEvents().getPopup(type: .scenario,
                                                     collection: String(scenarioID),
                                                     popupID: popupID
) else {
   print("Could not retrieve outro story sequence for scenario \(scenarioID) with popupID \(popupID).")
   return
}

let event: PopupEventPlayer? = PopupEventPlayer(delegate: self, model: model)
guard let popup = event else { return }
popup.id = popupID
self.view.addSubview(popup)

Or use anywhere with a locally created model:

func addPopup() {
   let model = PopupEvent(topText: "Made with ♥",
                          botText: "by Systers Open Source",
                          imgName: nil,
                          slideSound: nil,
                          badgeSound: nil)

   let popup: PopupEventPlayer = PopupEventPlayer(model)
   self.view.addSubview(popup)
}

Delegate methods: (optional)

func popupDidShow(sender: PopupEventPlayer)
func popupDidHide(sender: PopupEventPlayer)
func popupWasTapped(sender: PopupEventPlayer)

Author

Cadence Holmes 2018
  • Undocumented

    Declaration

    Swift

    weak var delegate: PopupEventPlayerDelegate?
  • id

    Undocumented

    Declaration

    Swift

    var id: Int?
  • Undocumented

    Declaration

    Swift

    let angleSize: CGFloat
  • Undocumented

    Declaration

    Swift

    let slideAnimDuration: Double
  • Undocumented

    Declaration

    Swift

    let popupDuration: Double
  • Undocumented

    Declaration

    Swift

    let fontName: String
  • Undocumented

    Declaration

    Swift

    var width: CGFloat
  • Undocumented

    Declaration

    Swift

    var height: CGFloat
  • Undocumented

    Declaration

    Swift

    var bgColor: UIColor
  • Undocumented

    Declaration

    Swift

    var borderColor: UIColor
  • Undocumented

    Declaration

    Swift

    var textColor: UIColor
  • Undocumented

    Declaration

    Swift

    var mainText: String?
  • Undocumented

    Declaration

    Swift

    var subText: String?
  • Undocumented

    Declaration

    Swift

    var image: UIImage?
  • Undocumented

    Declaration

    Swift

    var container: UIView
  • Undocumented

    Declaration

    Swift

    var mainLabel: UILabel
  • Undocumented

    Declaration

    Swift

    var subLabel: UILabel
  • Undocumented

    Declaration

    Swift

    var imageView: UIImageView
  • Undocumented

    Declaration

    Swift

    var soundPlayer: SoundPlayer?
  • Undocumented

    Declaration

    Swift

    var slideSound: String?
  • Undocumented

    Declaration

    Swift

    var badgeSound: String?
  • Undocumented

    Declaration

    Swift

    let defaultSounds: (slideIn: String, showImage: String)
  • Undocumented

    Declaration

    Swift

    private var tapped: Bool
  • Undocumented

    See more

    Declaration

    Swift

    enum AccessibilityIdentifiers : String
  • Size and layout subviews.

    Declaration

    Swift

    private func setupSubviews()
  • Animate text labels upwards.

    Remark

    References slideAnimateDuration.

    Note

    See Animate .

    Declaration

    Swift

    private func animateLabelText(_ label: UILabel)

    Parameters

    label

    UILabel to be animated.

  • Updates the main and sub labels.

    Calls updateMainLabel() and updateSubLabel() .

    Declaration

    Swift

    func updateLabels()
  • Updates the main label.

    References relevant class properties and updates the upper text label with fade-in animations.

    Declaration

    Swift

    func updateMainLabel()
  • Updates the sub label.

    References relevant class properties and updates the lower text label with fade-in animations.

    Declaration

    Swift

    func updateSubLabel()
  • Updates the image view.

    References relevant class properties and updates the image view without animations. Animations are handled when the class is implemented and added to a superview.

    Declaration

    Swift

    func updateImageView()
  • Draws the inner container layer (angle and shadow).

    Also updates self.frame to conform to the inner containers bounds.

    Declaration

    Swift

    func updateContainer()
  • Draws the layer for the popup view, including the angled edge.

    Declaration

    Swift

    private func drawAngledShape() -> CAShapeLayer

    Return Value

    CAShapeLayer for the PopupEventPlayer view.

  • Animates showing the popup. Automatically called when an instance of PopupEventPlayer is added to a superview. See didMoveToSuperview() .

    Handles animations asyncronously on a background thread, checks for and plays sound, and times the popup for automatic dismissal.

    Declaration

    Swift

    func show()
  • Animates hiding the popup. Automatically called after show() + popupDuration , or when the popup is tapped.

    Handles animations asyncronously on a background thread, calls delegate method popupDidFinish(sender:).

    Declaration

    Swift

    func hide()
  • Animate sliding the popup into view.

    Declaration

    Swift

    private func animateSlideTo(x: CGFloat)

    Parameters

    x

    The distance to slide the popup.

  • Animate showing the badge image and call playSound().

    Declaration

    Swift

    private func animateShowImageWithSound()
  • Play a sound file once.

    Declaration

    Swift

    private func playSound(fileName: String?, volume: Float?)

    Parameters

    fileName

    The name of the audio asset to be played.

    volume

    The volume at which the sound is played.