@@ -5,6 +5,7 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
|
||||
|
||||
private let hiddenField = UITextField()
|
||||
private let stack = UIStackView()
|
||||
private let scrollView = UIScrollView()
|
||||
|
||||
private var chars: [String] = []
|
||||
private var blankPositions: [Int] = []
|
||||
@@ -21,7 +22,6 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
let scrollView = UIScrollView()
|
||||
scrollView.showsHorizontalScrollIndicator = false
|
||||
scrollView.showsVerticalScrollIndicator = false
|
||||
addSubview(scrollView)
|
||||
@@ -158,6 +158,22 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
|
||||
return box
|
||||
}
|
||||
refreshBoxes()
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.updateAlignment()
|
||||
}
|
||||
}
|
||||
|
||||
private func updateAlignment() {
|
||||
let totalWidth = CGFloat(chars.count) * 32 + CGFloat(max(chars.count - 1, 0)) * 6
|
||||
let available = scrollView.bounds.width
|
||||
if totalWidth <= available {
|
||||
let inset = max(0, (available - totalWidth) / 2)
|
||||
scrollView.contentInset = UIEdgeInsets(top: 0, left: inset, bottom: 0, right: inset)
|
||||
scrollView.isScrollEnabled = false
|
||||
} else {
|
||||
scrollView.contentInset = .zero
|
||||
scrollView.isScrollEnabled = true
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func boxTapped(_ gesture: UITapGestureRecognizer) {
|
||||
|
||||
Reference in New Issue
Block a user