Skip to content

Commit

Permalink
Adapt the text sticker input interface for iPad landscape mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Mar 22, 2024
1 parent 0a414ea commit 79611ba
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
4 changes: 1 addition & 3 deletions Sources/General/ZLClipImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ class ZLClipImageViewController: UIViewController {
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

guard shouldLayout else {
return
}
guard shouldLayout else { return }
shouldLayout = false

scrollView.frame = view.bounds
Expand Down
4 changes: 3 additions & 1 deletion Sources/General/ZLEditImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ open class ZLEditImageViewController: UIViewController {

open override var prefersHomeIndicatorAutoHidden: Bool { true }

override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { .portrait }
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
deviceIsiPhone() ? .portrait : .all
}

deinit {
cleanToolViewStateTimer()
Expand Down
8 changes: 8 additions & 0 deletions Sources/General/ZLImageEditorDefine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ struct ZLImageEditorLayout {
static let bottomToolBtnCornerRadius: CGFloat = 5
}

func deviceIsiPhone() -> Bool {
return UIDevice.current.userInterfaceIdiom == .phone
}

func deviceIsiPad() -> Bool {
return UIDevice.current.userInterfaceIdiom == .pad
}

func deviceSafeAreaInsets() -> UIEdgeInsets {
var insets: UIEdgeInsets = .zero

Expand Down
46 changes: 37 additions & 9 deletions Sources/General/ZLInputTextViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ class ZLInputTextViewController: UIViewController {

private var textStyle: ZLInputTextStyle

private lazy var bgImageView: UIImageView = {
let view = UIImageView(image: image?.zl.blurImage(level: 4))
view.contentMode = .scaleAspectFit
return view
}()

private lazy var coverView: UIView = {
let view = UIView()
view.backgroundColor = .black
view.alpha = 0.4
return view
}()

private lazy var cancelBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setTitle(localLanguageTextValue(.cancel), for: .normal)
Expand All @@ -64,8 +77,7 @@ class ZLInputTextViewController: UIViewController {
}()

private lazy var textView: UITextView = {
let y = max(deviceSafeAreaInsets().top, 20) + 20 + ZLImageEditorLayout.bottomToolBtnH + 12
let textView = UITextView(frame: CGRect(x: 10, y: y, width: view.zl.width - 20, height: 200))
let textView = UITextView()
textView.keyboardAppearance = .dark
textView.returnKeyType = .done
textView.delegate = self
Expand Down Expand Up @@ -114,6 +126,8 @@ class ZLInputTextViewController: UIViewController {
return collectionView
}()

private var shouldLayout = true

private lazy var textLayer = CAShapeLayer()

private let textLayerRadius: CGFloat = 10
Expand Down Expand Up @@ -172,13 +186,29 @@ class ZLInputTextViewController: UIViewController {
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

guard shouldLayout else { return }

shouldLayout = false
bgImageView.frame = view.bounds

// iPad图片由竖屏切换到横屏时候填充方式会有点异常,这里重置下
if deviceIsiPad() {
if UIApplication.shared.statusBarOrientation.isLandscape {
bgImageView.contentMode = .scaleAspectFill
} else {
bgImageView.contentMode = .scaleAspectFit
}
}

let btnY = max(deviceSafeAreaInsets().top, 20) + 20
let cancelBtnW = localLanguageTextValue(.cancel).zl.boundingRect(font: ZLImageEditorLayout.bottomToolTitleFont, limitSize: CGSize(width: .greatestFiniteMagnitude, height: ZLImageEditorLayout.bottomToolBtnH)).width + 20
cancelBtn.frame = CGRect(x: 15, y: btnY, width: cancelBtnW, height: ZLImageEditorLayout.bottomToolBtnH)

let doneBtnW = localLanguageTextValue(.done).zl.boundingRect(font: ZLImageEditorLayout.bottomToolTitleFont, limitSize: CGSize(width: .greatestFiniteMagnitude, height: ZLImageEditorLayout.bottomToolBtnH)).width + 20
doneBtn.frame = CGRect(x: view.zl.width - 20 - doneBtnW, y: btnY, width: doneBtnW, height: ZLImageEditorLayout.bottomToolBtnH)

textView.frame = CGRect(x: 10, y: doneBtn.zl.bottom + 30, width: view.zl.width - 20, height: 200)

textStyleBtn.frame = CGRect(
x: 12,
y: 0,
Expand All @@ -197,17 +227,15 @@ class ZLInputTextViewController: UIViewController {
}
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
shouldLayout = true
}

func setupUI() {
view.backgroundColor = .black

let bgImageView = UIImageView(image: image?.zl.blurImage(level: 4))
bgImageView.frame = view.bounds
bgImageView.contentMode = .scaleAspectFit
view.addSubview(bgImageView)

let coverView = UIView(frame: bgImageView.bounds)
coverView.backgroundColor = .black
coverView.alpha = 0.4
bgImageView.addSubview(coverView)

view.addSubview(cancelBtn)
Expand Down

0 comments on commit 79611ba

Please sign in to comment.