質問編集履歴
1
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,4 +3,36 @@
|
|
3
3
|
下のリンクを参考にカーソル移動などを試みたのですがうまくいかなったです。
|
4
4
|
いい方法を教えていただけると嬉しいです。
|
5
5
|
|
6
|
-
[参考にした記事](https://riptutorial.com/ja/ios/example/13697/%E3%82%AB%E3%83%BC%E3%82%BD%E3%83%AB%E4%BD%8D%E7%BD%AE%E3%81%AE%E5%8F%96%E5%BE%97%E3%81%A8%E8%A8%AD%E5%AE%9A)
|
6
|
+
[参考にした記事](https://riptutorial.com/ja/ios/example/13697/%E3%82%AB%E3%83%BC%E3%82%BD%E3%83%AB%E4%BD%8D%E7%BD%AE%E3%81%AE%E5%8F%96%E5%BE%97%E3%81%A8%E8%A8%AD%E5%AE%9A)
|
7
|
+
|
8
|
+
DidBeginEditing内の出力では0が表示されるのですが、カーソルは移動してなかったです。
|
9
|
+
|
10
|
+
```swift
|
11
|
+
func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
|
12
|
+
if let selectedRange = textView.selectedTextRange {
|
13
|
+
|
14
|
+
textView.selectedRange.location = 0
|
15
|
+
|
16
|
+
let cursorPosition = textView.offset(from: textView.beginningOfDocument, to: selectedRange.start)
|
17
|
+
|
18
|
+
print(cursorPosition)
|
19
|
+
|
20
|
+
}
|
21
|
+
|
22
|
+
return true
|
23
|
+
}
|
24
|
+
|
25
|
+
func textViewDidBeginEditing(_ textView: UITextView) {
|
26
|
+
|
27
|
+
if let selectedRange = textView.selectedTextRange {
|
28
|
+
|
29
|
+
textView.selectedRange.location = 0
|
30
|
+
|
31
|
+
let cursorPosition = textView.offset(from: textView.beginningOfDocument, to: selectedRange.start)
|
32
|
+
|
33
|
+
print(cursorPosition)
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
}
|
38
|
+
```
|