Clean up image editor.
This commit is contained in:
parent
b64be3aa73
commit
fa08b18fd7
|
@ -89,20 +89,10 @@ class ImageEditorCropViewController: OWSViewController {
|
|||
|
||||
// MARK: - Buttons
|
||||
|
||||
// TODO: Apply icons.
|
||||
let doneButton = OWSButton(imageName: "image_editor_checkmark_full",
|
||||
tintColor: UIColor.white) { [weak self] in
|
||||
self?.didTapBackButton()
|
||||
}
|
||||
let rotate90Button = OWSButton(imageName: "image_editor_rotate",
|
||||
tintColor: UIColor.white) { [weak self] in
|
||||
self?.rotate90ButtonPressed()
|
||||
}
|
||||
// TODO: Myles may change this asset.
|
||||
let resetButton = OWSButton(imageName: "image_editor_undo",
|
||||
tintColor: UIColor.white) { [weak self] in
|
||||
self?.resetButtonPressed()
|
||||
}
|
||||
let flipButton = OWSButton(imageName: "image_editor_flip",
|
||||
tintColor: UIColor.white) { [weak self] in
|
||||
self?.flipButtonPressed()
|
||||
|
@ -113,18 +103,6 @@ class ImageEditorCropViewController: OWSViewController {
|
|||
}
|
||||
self.cropLockButton = cropLockButton
|
||||
|
||||
// MARK: - Header
|
||||
|
||||
let header = UIStackView(arrangedSubviews: [
|
||||
UIView.hStretchingSpacer(),
|
||||
resetButton,
|
||||
doneButton
|
||||
])
|
||||
header.axis = .horizontal
|
||||
header.spacing = 16
|
||||
header.backgroundColor = .clear
|
||||
header.isOpaque = false
|
||||
|
||||
// MARK: - Canvas & Wrapper
|
||||
|
||||
let wrapperView = UIView.container()
|
||||
|
@ -172,7 +150,6 @@ class ImageEditorCropViewController: OWSViewController {
|
|||
|
||||
let imageMargin: CGFloat = 20
|
||||
let stackView = UIStackView(arrangedSubviews: [
|
||||
header,
|
||||
wrapperView,
|
||||
footer
|
||||
])
|
||||
|
@ -217,6 +194,23 @@ class ImageEditorCropViewController: OWSViewController {
|
|||
updateClipViewLayout()
|
||||
|
||||
configureGestures()
|
||||
|
||||
updateNavigationBar()
|
||||
}
|
||||
|
||||
public func updateNavigationBar() {
|
||||
// TODO: Change this asset.
|
||||
let resetButton = navigationBarButton(imageName: "image_editor_undo",
|
||||
selector: #selector(didTapReset(sender:)))
|
||||
let doneButton = navigationBarButton(imageName: "image_editor_checkmark_full",
|
||||
selector: #selector(didTapDone(sender:)))
|
||||
var navigationBarItems = [UIView]()
|
||||
if transform.isNonDefault {
|
||||
navigationBarItems = [resetButton, doneButton]
|
||||
} else {
|
||||
navigationBarItems = [doneButton]
|
||||
}
|
||||
updateNavigationBar(navigationBarItems: navigationBarItems)
|
||||
}
|
||||
|
||||
private func updateCropLockButton() {
|
||||
|
@ -354,6 +348,7 @@ class ImageEditorCropViewController: OWSViewController {
|
|||
applyTransform()
|
||||
updateClipViewLayout()
|
||||
updateImageLayer()
|
||||
updateNavigationBar()
|
||||
|
||||
CATransaction.commit()
|
||||
}
|
||||
|
@ -731,7 +726,7 @@ class ImageEditorCropViewController: OWSViewController {
|
|||
|
||||
// MARK: - Events
|
||||
|
||||
@objc public func didTapBackButton() {
|
||||
@objc func didTapDone(sender: UIButton) {
|
||||
completeAndDismiss()
|
||||
}
|
||||
|
||||
|
@ -771,7 +766,9 @@ class ImageEditorCropViewController: OWSViewController {
|
|||
isFlipped: !transform.isFlipped).normalize(srcImageSizePixels: model.srcImageSizePixels))
|
||||
}
|
||||
|
||||
@objc public func resetButtonPressed() {
|
||||
@objc func didTapReset(sender: UIButton) {
|
||||
Logger.verbose("")
|
||||
|
||||
updateTransform(ImageEditorTransform.defaultTransform(srcImageSizePixels: model.srcImageSizePixels))
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,10 @@ public class ImageEditorTransform: NSObject {
|
|||
isFlipped: false).normalize(srcImageSizePixels: srcImageSizePixels)
|
||||
}
|
||||
|
||||
public var isNonDefault: Bool {
|
||||
return !isEqual(ImageEditorTransform.defaultTransform(srcImageSizePixels: outputSizePixels))
|
||||
}
|
||||
|
||||
public func affineTransform(viewSize: CGSize) -> CGAffineTransform {
|
||||
let translation = unitTranslation.fromUnitCoordinates(viewSize: viewSize)
|
||||
// Order matters. We need want SRT (scale-rotate-translate) ordering so that the translation
|
||||
|
|
|
@ -10,6 +10,9 @@ public protocol ImageEditorPaletteViewDelegate: class {
|
|||
|
||||
// MARK: -
|
||||
|
||||
// We represent image editor colors using this (color, phase)
|
||||
// tuple so that we can consistently restore palette view
|
||||
// state.
|
||||
@objc
|
||||
public class ImageEditorColor: NSObject {
|
||||
public let color: UIColor
|
||||
|
|
|
@ -449,7 +449,7 @@ public class ImageEditorView: UIView {
|
|||
|
||||
let cropTool = ImageEditorCropViewController(delegate: self, model: model, srcImage: srcImage, previewImage: previewImage)
|
||||
self.delegate?.imageEditor(presentFullScreenOverlay: cropTool,
|
||||
withNavigation: false)
|
||||
withNavigation: true)
|
||||
}}
|
||||
|
||||
// MARK: -
|
||||
|
|
Loading…
Reference in New Issue