EditController
@objcMembers
public class EditController : UIViewController
The primary functionality of the EditController
includes filter selection, filter intensity, adjustments (brightness, vibrance, saturation, etc.), cropping, rotation, horizontal/vertical perspective correction, and video
segment composing/trimming/re-ordering.
The edit controller is always presented with an image or video based Session
object. Sessions can be edited programmatically by changing filters, crop rects, trim times and more. The
edit controller will display all programmatic changes to a session in its interface. For more information on modifying a session see the Session
documentation.
When presented with an image based session, the controller consists of two tabs Filter and Adjust. When presented with a video, the controller consists of three tabs Filter, Trim and Adjust. You may edit media of any aspect ratio. All editing functionality available to images is also available to videos.
Normally the edit controller is pushed onto the navigation stack by either the LibraryController
or CameraController
. You may also present the edit controller manually with a Session
for example:
let image = UIImage(named: "test_image")!
let session = Session(image: image)
let editController = EditController(session: session)
editController.delegate = self
let nav = UINavigationController(rootViewController: editController)
nav.modalPresentationStyle = .fullScreen
self.present(nav, animated: true, completion: nil)
Attention
Sessions are automatically saved so you a responsible for callingdestroy()
when you are done with a session (unless noted otherwise). If you do
not destroy a session it will persist in the users Drafts in memory and on disk.
You may also present an edit controller with one or more AVAssets, for example:
let asset1 = AVAsset(url: Bundle.main.url(forResource: "test", withExtension: "mov")!)
let asset2 = AVAsset(url: Bundle.main.url(forResource: "test2", withExtension: "mp4")!)
let _ = Session(assets: [asset1, asset2], sessionReady: { (session, error) in
guard let session = session else {
print("Unable to create session: \(error!)")
return
}
let editController = EditController(session: session)
editController.delegate = self
let nav = UINavigationController(rootViewController: editController)
nav.modalPresentationStyle = .fullScreen
self.present(nav, animated: true, completion: nil)
})
Filters under the Filter or Adjust tabs may be changed by setting the primaryFilters
adjustmentFilters
variables respectively.
The Adjust tab places the Position (cropping) button before the adjust filters. Cropping can be disabled by setting showsPositionAdjustment
to false.
-
Creates an
EditController
with the provided session. The session you pass here will be automatically saved when any changes are made by the controller.Warning
Modifying the session after the controller has been presented may result in undocumented behavior.
Precondition
Provided session must not be destroyed.
Declaration
Swift
public init(session: Session)
Parameters
session
The session to initialize the
EditController
with.
-
The session the
EditController
was initialized with.Declaration
Swift
public let session: Session
-
The edit controller view consists of a tab bar at the bottom and a small controller above it. Each tab is represented by a
EditMode
with an associated controller and title for the tab. The modes you provide here will be represented in the containers tab bar in their respective order.If you wish to provide your own controller, use the
.custom(title:controller:)
enum value.Warning
If you do not include
.trim
in your modes, the edit controller will be unable to enforce maximum video duration. You will have to implement logic for enforcing maximum duration yourself.Precondition
You must provide at least one mode.
Default value:
[.filter, .trim, .adjust]
Declaration
Swift
public var modes: [EditMode] { get set }
-
The mode that is currently visible.
Default value:
.filter
Declaration
Swift
public private(set) var currentMode: EditMode { get }
-
Set this delegate in order to handle events that occur in this controller.
Default value:
nil
Declaration
Swift
public weak var delegate: EditControllerDelegate? { get set }
-
The back button in the top left corner of this controller.
Declaration
Swift
@IBOutlet public private(set) var backButton: UIButton! { get }
-
The Next button in the top right corner of this controller.
Declaration
Swift
@IBOutlet public private(set) var nextButton: UIButton! { get }
-
When “Keep Draft” is pressed in the save dialogue, no action is taken since the session has already been automatically saved. When “Discard” is pressed in the save dialogue, the session is destroyed by calling
destroy()
.If this is true, the controller may show the save dialogue when the back button is pressed.
isTransient
must be false and there must have been changes to the session for a save dialogue to appear.If this is false, no save dialogue will be shown when the back button button is pressed.
For all cases where no save dialogue appears, the session will stay saved and
destroy()
will not be called.Default value:
true
Declaration
Swift
public var showsSaveDialogue: Bool
-
If you would like to disable cropping, rotation and horizontal/vertical perspective correction set this to false. This will hide the Position button found in the Adjust tab.
Default value:
true
Declaration
Swift
public var showsPositionAdjustment: Bool
-
Set this to true if you want to reduce the height of the editor controls and increase the height of the media preview. This can improve the user experience if portrait content is edited frequently.
If this controller is presented by a
LibraryController
orCameraController
with a portrait aspect ratio, the default value may betrue
instead offalse
.Default value:
false
Declaration
Swift
public var compactControls: Bool { get set }