SpriteController
@objc(PESDKSpriteController) open class SpriteController: NSObject
An SpriteController
manages all sprites that have been added to an image and hosts the
sprite’s container view.
-
The parent view that the container was added to.
Declaration
Swift
open let parentView: UIView
-
The container view that hosts all sprites.
Declaration
Swift
open let view = UIView()
-
The base image. Needed for some calculations.
Declaration
Swift
open var baseImage: CIImage?
-
The frame and its image that is currently added as an sprite.
Declaration
Swift
open var frame: (Frame, UIImage)?
-
An
UIImage
of the painting to use as an sprite.Declaration
Swift
open var painting: UIImage?
-
The image view that displays the painting.
Declaration
Swift
private(set) open var paintingImageView = BrushImageView()
-
The image view that displays the frame.
Declaration
Swift
private(set) open var frameImageView = FrameImageView()
-
The undo controller associated with this sprite controller.
Declaration
Swift
open let undoController: UndoController
-
The currently selected sprite.
Declaration
Swift
open var selectedSpriteView: UIView?
-
A handler that should be called when the currently selected sprite changes.
Declaration
Swift
open var selectionChangedHandler: ((_ previousSelection: UIView?, _ newSelection: UIView?) -> Void)?
-
An array of sprites that have been added to the sprite controller. This excludes the painting and frame.
Declaration
Swift
open var sprites: [UIView]
-
Whether or not any sprites are added.
Declaration
Swift
open var spritesAdded: Bool
-
Adds a sticker image view as a sprite.
Declaration
Swift
open func addStickerImageView(_ imageView: StickerImageView)
Parameters
imageView
The sticker image view to add.
-
Adds a sticker as an sprite.
Declaration
Swift
@discardableResult open func addSticker(_ sticker: Sticker, with image: UIImage, select: Bool, completion: ((UIImageView) -> Void)?) -> UIImageView
Parameters
sticker
The sticker that should be added.
image
The image of the sticker.
select
Whether or not the sticker should be selected after it was added.
completion
A completion handler to run after the sticker was added.
Return Value
The image view that was added.
-
Adds text as an sprite.
Declaration
Parameters
text
The text to add as an sprite.
color
The color of the text.
select
Whether or not the text should be selected after it was added.
completion
A completion handler to run after the sticker was added.
Return Value
The text label that was added.
-
Add a text label to the sprite controller.
Declaration
Swift
open func addTextLabel(_ label: TextLabel)
Parameters
label
A label.
-
Adds a frame as an sprite.
Declaration
Swift
@objc(addFrame:withImage:) open func addFrame(_ frame: Frame, with image: UIImage)
Parameters
frame
The frame to add to the image.
image
The image to add to the image.
-
Removes the current frame as an sprite.
Declaration
Swift
open func removeFrame()
-
Moves the currently selected sprite to the front.
Declaration
Swift
open func bringSelectedSpriteToFront()
-
Moves the passed sprite to the front.
Declaration
Swift
open func bringSprite(toFront sprite: UIView)
Parameters
sprite
The sprite to move to the front.
-
Moves the passed sprite to the specified index.
Declaration
Swift
open func moveSprite(_ sprite: UIView, toIndex index: Int)
Parameters
sprite
The sprite to move.
index
The index to move to.
-
Moves the painting to the front.
Declaration
Swift
open func bringPaintingToFront()
-
Moves the frame to the front.
Declaration
Swift
open func bringFrameToFront()
-
Moves the frame to the back.
Declaration
Swift
open func sendFrameToBack()
-
Whether or not the frame is in front of the sprites.
Declaration
Swift
open var isFrameInFront: Bool
-
Resets the rotation of the currently selected sprite.
Declaration
Swift
open func straightenSelectedSprite()
-
Resets the rotation of the passed sprite.
Declaration
Swift
open func straightenSprite(_ sprite: UIView)
Parameters
sprite
The sprite to reset.
-
Rotates the passed sprite be the specified radians.
Declaration
Swift
open func rotateSprite(_ sprite: UIView, byRadians radians: CGFloat)
Parameters
sprite
The sprite to rotate.
radians
The amount of radians to rotate by.
-
Transforms the passed sprite from the specified transform to the other specified transform.
Declaration
Swift
open func transformSprite(_ sprite: UIView, from startTransform: CGAffineTransform, to endTransform: CGAffineTransform)
Parameters
sprite
The sprite to transform.
startTransform
The start transform (this is only used for undo).
endTransform
The transform to apply to the sprite.
-
Resizes the passed sprite from the specified rect to the other specified rect.
Declaration
Swift
open func resizeSprite(_ sprite: UIView, from startBounds: CGRect, to endBounds: CGRect)
Parameters
sprite
The sprite to resize.
startBounds
The start rect (this is only used for undo).
endBounds
The rect to resize the sprite to.
-
Moves the passed sprite from the specified point to the other specified point.
Declaration
Swift
open func moveSprite(_ sprite: UIView, from startPoint: CGPoint, to endPoint: CGPoint)
Parameters
sprite
The sprite to move.
startPoint
The start point (this is only used for undo).
endPoint
The point to move the sprite to.
-
Moves and resizes the sprite.
Declaration
Swift
open func moveSprite(_ sprite: UIView, from startPoint: CGPoint, to endPoint: CGPoint, resizingFrom startBounds: CGRect, toRect toBounds: CGRect)
Parameters
sprite
The sprite to move and resize.
startPoint
The start point (this is only used for undo).
endPoint
The point to move the sprite to.
startBounds
The start rect (this is only used for undo).
toBounds
The rect to resize the sprite to.
-
Flips the currently selected sprite horizontally.
Declaration
Swift
open func flipSelectedSprite()
-
Flips the passed sprite horizontally. Currently only supports stickers.
Declaration
Swift
open func flipSprite(_ sprite: UIView)
Parameters
sprite
The sprite to flip.
-
Changes the tint or background color (where appropriate) of an sprite.
Declaration
Swift
open func changeSprite(_ sprite: UIView, from fromColor: UIColor, to toColor: UIColor, changeBackground: Bool)
Parameters
sprite
The sprite to change the color for.
fromColor
The start color (this is only used for undo).
toColor
The color to change to.
changeBackground
When
true
the background color is changed (where possible).
-
Changes the font of a text label.
Declaration
Swift
open func changeTextLabel(_ label: TextLabel, from fromFont: UIFont, to toFont: UIFont)
Parameters
label
The label to change the font of.
fromFont
The start font (this is only used for undo).
toFont
The font to change to.
-
Changes the text of a label.
Declaration
Swift
open func changeTextLabel(_ label: TextLabel, fromText: String?, toText: String?)
Parameters
label
The label to change the text of.
fromText
The text to change from (this is only used for undo).
toText
The text to change to.
-
Changes the text alignment of a label.
Declaration
Swift
open func changeTextLabel(_ label: TextLabel, fromAlignment: NSTextAlignment, toAlignment: NSTextAlignment)
Parameters
label
The label to change the alignment of.
fromAlignment
The alignment to change from (this is only used for undo).
toAlignment
The alignment to change to.
-
Removes the currently selected sprite.
Declaration
Swift
open func removeSelectedSprite()
-
Removes the currently selected sprite.
Declaration
Swift
open func remove(sprite: UIView)