StorySequencePlayer

class StorySequencePlayer : UIView

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

Example use:

let scenarioID = 5
guard let model = StorySequences().getStorySequence(scenario: scenarioID) else {
print("Could not retrieve intro story sequence for scenario \(scenarioID).")
return
}

let sequenceView: StorySequencePlayer = StorySequencePlayer(delegate: self, model: model, firstTime: firstTime())
self.view.addSubview(sequenceView)

Delegate methods: (optional)

func sequenceDidStart(sender: StorySequencePlayer)
func sequenceDidFinish(sender: StorySequencePlayer)
func sequenceWasSkipped(sender: StorySequencePlayer)

Author

Cadence Holmes 2018
  • Undocumented

    Declaration

    Swift

    weak var delegate: StorySequencePlayerDelegate?
  • Undocumented

    Declaration

    Swift

    let fontName: String
  • Undocumented

    Declaration

    Swift

    let fontSize: CGFloat
  • Undocumented

    Declaration

    Swift

    let indicatorImage: String
  • Undocumented

    Declaration

    Swift

    let baseAnimDuration: Double
  • Undocumented

    Declaration

    Swift

    var textContainer: UIView
  • Undocumented

    Declaration

    Swift

    var imageViewContainer: UIView
  • Undocumented

    Declaration

    Swift

    var leftImageView: UIImageView
  • Undocumented

    Declaration

    Swift

    var rightImageView: UIImageView
  • Undocumented

    Declaration

    Swift

    var indicator: UIImageView
  • Undocumented

    Declaration

    Swift

    var model: StorySequence
  • Undocumented

    Declaration

    Swift

    var currentStep: Int
  • Undocumented

    Declaration

    Swift

    var imgNear: CGFloat
  • Undocumented

    Declaration

    Swift

    var imgMid: CGFloat
  • Undocumented

    Declaration

    Swift

    var imgFar: CGFloat
  • Undocumented

    Declaration

    Swift

    var soundPlayer: SoundPlayer
  • Undocumented

    Declaration

    Swift

    private var canTap: Bool
  • Undocumented

    Declaration

    Swift

    private var lastImages: Array<String?>
  • Undocumented

    Declaration

    Swift

    private var lastPositions: Array<StorySequence.ImagePosition>
  • For easy access to accessibility identifiers used in testing.

    See more

    Declaration

    Swift

    enum AccessibilityIdentifiers : String
  • Add a full screen blurred view as the background layer.

    Declaration

    Swift

    private func addBlur(_ view: UIView, _ style: UIBlurEffectStyle)

    Parameters

    view

    Target UIView.

    style

    Desired UIBlueEffectStyle.

  • Test for iPhone X to be able to adjust for the black area in the larger status bar.

    Declaration

    Swift

    private func isIphoneX() -> Bool

    Return Value

    true if the user device is a phone with pixel height 2436.

  • Declaration

    Swift

    private func iPhoneXStatusBarHeight() -> CGFloat

    Return Value

    44 pixels.

  • Layout the image container in the main view, layout the imageviews in the image container, also add the indicator view

    Declaration

    Swift

    private func layoutImageViews(_ margin: CGFloat, _ height: CGFloat)

    Parameters

    margin

    The margin to pad either side of the container.

    height

    The intended height of the image containers.

  • Layout the main text container. Parent container for the left and right text containers.

    Declaration

    Swift

    private func layoutTextContainer(_ margin: CGFloat, _ height: CGFloat)

    Parameters

    margin

    The margin to pad either side of the container.

    height

    The intended height of the text containers.

  • Add a tap gesture to manually step through the story sequence.

    Declaration

    Swift

    private func addTapGesture()
  • Check if the view is tappable. If so, call checkCurrentStep() .

    Declaration

    Swift

    @objc
    private func tapView(_ sender: UITapGestureRecognizer)
  • Add a long press gesture to skip the story sequence.

    Declaration

    Swift

    private func addLPGesture()
  • Check if a long press has begun. If so, call displaySkipWarning() .

    Declaration

    Swift

    @objc
    private func lpView(_ sender: UILongPressGestureRecognizer)
  • Create and display an interactive warning view. User must ascert their intention to skip the story sequence.

    Declaration

    Swift

    private func displaySkipWarning()
  • Called when from the warning view shown by displaySkipWarning() . Either dismiss the warning, or proceed with skipping the story sequence.

    Skipping dismisses and releases the view, and calls the delegate method sequenceWasSkipped(sender:).

    Declaration

    Swift

    @objc
    private func tapSkipButton(_ sender: UIButton?)
  • Check if there is another step in the sequence, update own count and call UI updates, else hide and dismiss.

    Called when the view is tapped.

    Declaration

    Swift

    private func checkCurrentStep()
  • Update the layout for both sides to the currentStep . Wait for animations to complete before re-enabling interactions.

    Declaration

    Swift

    private func updateToCurrentStep()
  • Update the layout of the left side to the currentStep . Automatically handles all animations and changes based on the data in the model.

    Declaration

    Swift

    private func updateLeftSide()
  • Update the layout of the right side to the currentStep . Automatically handles all animations and changes based on the data in the model.

    Declaration

    Swift

    private func updateRightSide()
  • Create a formatted label to use as unbound text bubbles.

    Declaration

    Swift

    private func makeLabel(text: String, left: Bool) -> UILabel

    Parameters

    text

    The text to be used.

    left

    If true, label is formatted to be used on the left side, otherwise it is formatted for the right side.

    Return Value

    A properly formatted UILabel ready to be inserted in the view hierarchy.

  • Handles shifting all of the subviews of textContainer .

    Declaration

    Swift

    private func shiftLabels()
  • Returns a random CGFloat 0 - 1.

    Declaration

    Swift

    private func randomCGFloat() -> CGFloat
  • Change the image of the imageView.

    Remarks

    This function originally included animation instructions as well. Even though it’s simplified to the point of not really being necessary, it has been left in case animations need to be added again.

    Declaration

    Swift

    private func changeImage(imageView: UIImageView, image: String)
  • Determing the horizontal position to move an image to and animate the imageView to the position.

    Declaration

    Swift

    private func moveImage(pos: StorySequence.ImagePosition, view: UIImageView, left: Bool, dur: Double)

    Parameters

    pos

    enum StorySequence.ImagePosition describing the target position.

    view

    Target UIImageView.

    left

    If true, pos cases will be calculated for the left side of the view container. Otherwise pos will be calculated for the right side.

    dur

    The duration of the animation. This is variable since this function is used differently depending on whether or not the entire character image or just the character type/mood has changed.

  • Hide the indicator when the view is not interactive.

    Declaration

    Swift

    private func hideIndicator()
  • Show the indicator when the view is interactive.

    Declaration

    Swift

    private func showIndicator()
  • Handle blinking the indicator when visible, or turning off the animation when hidden.

    Declaration

    Swift

    private func blinkIndicator()
  • Handle the animations for an image. This is the animation specific to the step, not the universal animations used when changing position.

    All of the animation instructions are in this function. When designing/adding new animation options, the case and instructions should be added here as well as in enum StorySequence.ImageAnimation. New options also need to be synced with the PowerUp Story Designer web app.

    Declaration

    Swift

    private func doAnimation(anim: StorySequence.ImageAnimation, view: UIView)

    Parameters

    anim

    enum StorySequence.ImageAnimation case for the desired animation. Provided by the model.

    view

    Target UIView to be animated.

  • Handles hiding and dismissing the StorySequencePlayer view.

    Ends sound, animates the view to hidden, and removes this instance of StorySequencePlayer from its superview.

    Also calls the delegate method sequenceDidFinish(sender:).

    Declaration

    Swift

    func hide()