Compare commits
8 Commits
f1a380d105
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a525c763e | |||
| a0dffdc715 | |||
| 4765d48021 | |||
| f888e28d15 | |||
| c934dbad84 | |||
| 4088db8ec0 | |||
| 255f171aa8 | |||
| 70870e1ec2 |
@@ -184,6 +184,7 @@
|
|||||||
knownRegions = (
|
knownRegions = (
|
||||||
en,
|
en,
|
||||||
Base,
|
Base,
|
||||||
|
"zh-Hans",
|
||||||
);
|
);
|
||||||
mainGroup = CFD40B073003C283009C9F2A;
|
mainGroup = CFD40B073003C283009C9F2A;
|
||||||
minimizedProjectReferenceProxies = 1;
|
minimizedProjectReferenceProxies = 1;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import UIKit
|
|||||||
class ClipEditViewController: UIViewController {
|
class ClipEditViewController: UIViewController {
|
||||||
|
|
||||||
private var textView: UITextView!
|
private var textView: UITextView!
|
||||||
|
private var floatingDoneButton: UIButton!
|
||||||
|
private var floatingDoneButtonBottomConstraint: NSLayoutConstraint!
|
||||||
private var clip: Clip
|
private var clip: Clip
|
||||||
|
|
||||||
init(clip: Clip) {
|
init(clip: Clip) {
|
||||||
@@ -29,6 +31,45 @@ class ClipEditViewController: UIViewController {
|
|||||||
|
|
||||||
setupNavigationBar()
|
setupNavigationBar()
|
||||||
setupTextView()
|
setupTextView()
|
||||||
|
setupKeyboardObservers()
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
NotificationCenter.default.removeObserver(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupKeyboardObservers() {
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func keyboardWillShow(_ notification: Notification) {
|
||||||
|
guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
|
||||||
|
let keyboardFrameInView = view.convert(keyboardFrame, from: nil)
|
||||||
|
let intersection = keyboardFrameInView.intersection(view.bounds)
|
||||||
|
let keyboardHeight = intersection.height
|
||||||
|
|
||||||
|
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
|
||||||
|
|
||||||
|
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
|
||||||
|
self.textView.contentInset.bottom = keyboardHeight
|
||||||
|
self.textView.verticalScrollIndicatorInsets.bottom = keyboardHeight
|
||||||
|
self.floatingDoneButtonBottomConstraint.constant = -(keyboardHeight + 8)
|
||||||
|
self.floatingDoneButton.alpha = 1
|
||||||
|
self.view.layoutIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func keyboardWillHide(_ notification: Notification) {
|
||||||
|
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
|
||||||
|
|
||||||
|
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
|
||||||
|
self.textView.contentInset.bottom = 0
|
||||||
|
self.textView.verticalScrollIndicatorInsets.bottom = 0
|
||||||
|
self.floatingDoneButtonBottomConstraint.constant = -16
|
||||||
|
self.floatingDoneButton.alpha = 0
|
||||||
|
self.view.layoutIfNeeded()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
@@ -61,15 +102,40 @@ class ClipEditViewController: UIViewController {
|
|||||||
textView.text = clip.text
|
textView.text = clip.text
|
||||||
view.addSubview(textView)
|
view.addSubview(textView)
|
||||||
|
|
||||||
|
var doneConfig = UIButton.Configuration.glass()
|
||||||
|
doneConfig.title = "完成"
|
||||||
|
doneConfig.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
|
||||||
|
var outgoing = incoming
|
||||||
|
outgoing.font = UIFont.systemFont(ofSize: 17, weight: .semibold)
|
||||||
|
return outgoing
|
||||||
|
}
|
||||||
|
doneConfig.baseForegroundColor = .label
|
||||||
|
doneConfig.cornerStyle = .capsule
|
||||||
|
doneConfig.contentInsets = NSDirectionalEdgeInsets(top: 15, leading: 22, bottom: 15, trailing: 22)
|
||||||
|
floatingDoneButton = UIButton(configuration: doneConfig)
|
||||||
|
floatingDoneButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
floatingDoneButton.alpha = 0
|
||||||
|
floatingDoneButton.addTarget(self, action: #selector(didTapFloatingDoneButton), for: .touchUpInside)
|
||||||
|
view.addSubview(floatingDoneButton)
|
||||||
|
|
||||||
let safeArea = view.safeAreaLayoutGuide
|
let safeArea = view.safeAreaLayoutGuide
|
||||||
|
floatingDoneButtonBottomConstraint = floatingDoneButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -16)
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
textView.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 16),
|
textView.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 16),
|
||||||
textView.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor, constant: 16),
|
textView.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor, constant: 16),
|
||||||
textView.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -16),
|
textView.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -16),
|
||||||
textView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -16)
|
textView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -16),
|
||||||
|
|
||||||
|
floatingDoneButton.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -16),
|
||||||
|
floatingDoneButtonBottomConstraint
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc private func didTapFloatingDoneButton() {
|
||||||
|
textView.resignFirstResponder()
|
||||||
|
}
|
||||||
|
|
||||||
@objc private func didTapSaveButton() {
|
@objc private func didTapSaveButton() {
|
||||||
let updatedText = textView.text ?? ""
|
let updatedText = textView.text ?? ""
|
||||||
guard !updatedText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
guard !updatedText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
||||||
|
|||||||
@@ -246,8 +246,10 @@ extension ClipInboxViewController: UITableViewDataSource {
|
|||||||
|
|
||||||
var config = cell.defaultContentConfiguration()
|
var config = cell.defaultContentConfiguration()
|
||||||
config.text = previewText(for: clip.text)
|
config.text = previewText(for: clip.text)
|
||||||
|
config.textProperties.numberOfLines = 0
|
||||||
config.secondaryText = formattedDate(clip.createdAt)
|
config.secondaryText = formattedDate(clip.createdAt)
|
||||||
config.secondaryTextProperties.color = .secondaryLabel
|
config.secondaryTextProperties.color = .secondaryLabel
|
||||||
|
config.textToSecondaryTextVerticalPadding = 12
|
||||||
cell.contentConfiguration = config
|
cell.contentConfiguration = config
|
||||||
cell.accessoryType = .disclosureIndicator
|
cell.accessoryType = .disclosureIndicator
|
||||||
|
|
||||||
@@ -255,9 +257,7 @@ extension ClipInboxViewController: UITableViewDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func previewText(for text: String) -> String {
|
private func previewText(for text: String) -> String {
|
||||||
let lines = text.components(separatedBy: .newlines)
|
let preview = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
let firstTwoLines = Array(lines.prefix(2))
|
|
||||||
let preview = firstTwoLines.joined(separator: " ").trimmingCharacters(in: .whitespaces)
|
|
||||||
if preview.isEmpty {
|
if preview.isEmpty {
|
||||||
return "(无内容)"
|
return "(无内容)"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,10 +35,6 @@ class FormatNoteViewController: UIViewController {
|
|||||||
setupUI()
|
setupUI()
|
||||||
if let initialText = initialText {
|
if let initialText = initialText {
|
||||||
textView.text = initialText
|
textView.text = initialText
|
||||||
isNoteFormatted = true
|
|
||||||
noteButton.setTitle("复制并打开备忘录", for: .normal)
|
|
||||||
rightBarButtonMode = .reset
|
|
||||||
updateRightBarButtonItem()
|
|
||||||
}
|
}
|
||||||
setupKeyboardObservers()
|
setupKeyboardObservers()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
/* Simplified Chinese localization */
|
||||||
Reference in New Issue
Block a user