Instance Property

time

The time offset, in seconds, of this frame relative to the start of the Live Photo.

Required.

Declaration

var time: CMTime { get }

Discussion

You can use this value to vary your image processing over time, creating animated effects. For example, the following code sets up an animated filter that fades from sepia tone to original to sepia tone again over the duration of the Live Photo:

 
// Save properties of the context to avoid capturing it in the closure.
let duration = CMTimeGetSeconds(context.duration)
let photoTime = CMTimeGetSeconds(context.photoTime)
// Frame processor closure uses duration/photoTime/frameTime to animate.
context.frameProcessor = { frame, _ in
    let frameTime = CMTimeGetSeconds(frame.time)
    let intensity: Double
    if frameTime < photoTime {
        // Vary intensity from -1.0 to 0.0 before the photo.
        intensity = -frameTime / photoTime
    } else {
        // Vary intensity from 0.0 to 1.0 after the photo.
        intensity = (frameTime - photoTime) / (duration - photoTime)
    }
    return frame.image.applyingFilter("CISepiaTone",
        withInputParameters: [ kCIInputIntensityKey: intensity ])
}

See Also

Getting Information About the Frame

var renderScale: CGFloat

The scale factor of the frame image relative to the Live Photo’s photo content.

Required.

var type: PHLivePhotoFrameType

The type of image content in this frame.

Required.

enum PHLivePhotoFrameType

Identifiers for the type of frame image to be processed. Used with the type property.