Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ノートアプリにUndo機能を実装! UndoManager導入ポイント
Search
watura
August 24, 2024
0
490
ノートアプリにUndo機能を実装! UndoManager導入ポイント
iOSDC 2024 LT
watura
August 24, 2024
Tweet
Share
More Decks by watura
See All by watura
Ruby note Mobile Tech Talk #1
watura
0
1.5k
iPhone が数秒おきにクラッシュするんだけど!
watura
0
9
Swift Scripting入門
watura
0
120
2つのAuroraクラスタを同期したお話
watura
0
1.6k
Zaim API
watura
1
720
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
526
40k
Producing Creativity
orderedlist
PRO
347
40k
How STYLIGHT went responsive
nonsquared
100
5.8k
The Illustrated Children's Guide to Kubernetes
chrisshort
49
51k
Unsuck your backbone
ammeep
671
58k
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.8k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
45
2.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
35
6.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Transcript
UndoManager導入ポイント ノートアプリにUndo機能を実装! watura note 株式会社 iOS アプリエンジニア https://wtr.app iOSDC 2024
LT
お疲れ さまです
Undo Manager
使って ます?
Undo Manager
iOS 3.0+
Undo/ Redoのた めの
スタック
ス
タ ス
ク タ ス
Undo
タ ス
ッ タ ス
ク ッ タ ス
後入 先出
にUndo機能を実装しようとして苦労した話 iOS版
使い方
register Undo(...) { } クを消す
UndoManager. undo()
Redo?
registerUndo { } クを消す registerUndo { クを入力 }
UndoManager. redo()
簡単!
最高!
Grouping
複数の
Undoを
1つの
Undoと みなす
便利 機能
一連の 文字入力
いっぺんに undoされる
謎のブロック ごと
iOSさんが
いい感じに
まとめて くれる
もちろん
手動でも 管理できる
beginUndoGrouping endUndoGrouping
beginUndoGrouping() undoTask("Undo 1") endUndoGrouping() beginUndoGrouping() undoTask("Undo 2") endUndoGrouping() beginUndoGrouping() undoTask("Undo
3") endUndoGrouping()
undo() → Undo3 undo() → Undo2 undo() → Undo1
ってなると 思うでしょ?
undo() → Undo3 Undo2 Undo1
みんな まとめて Undo!!!
iOSさんが Grouping いい感じに
無理やりwait をいれる スレッドとか
undo() → Undo3 undo() → Undo2 undo() → Undo1
全部
手動
groupsByEvent = false
beginUndoGrouping() undoTask("Undo 1") endUndoGrouping() beginUndoGrouping() undoTask("Undo 2") endUndoGrouping() beginUndoGrouping() undoTask("Undo
3") endUndoGrouping()
undo() → Undo3 undo() → Undo2 undo() → Undo1
beginを
忘れていたら
クラッシュ
クラッ シュ
まだまだ続くよ 問題点
UITextView
_UITextUndoManager
_UITextUndoManager
iOSっぽい テキストの Undo
Undoの 自動登録
override
undoに
登録されない
手動で 登録
iOSっぽい テキストの Undo
いい感じには 難しい
諦めた
固有の問題点
https://note.com/fromkk/n/ne14f81e62e3f
TextView ImageView TextView StackView エディタの構造
TextView1 TextView2 Undo Manager Undo Manager
TextView それぞれが
Undo Manager をもつ
TextView1 TextView2 変更3 変更1 変更2
Undoボタン 連打で
変更3 変更2 変更1
全部 戻したい
できない
Responder Chainが別
TextView1 TextView2 変更3 変更1 変更2 知らない子 ⇔
TextView1 TextView2 オレオレUndoManager
_UITextUndoManager
オレオレ UndoManager 作れない
通知が飛んで 来たら
UndoManger を スタックする
NSUndoManager DidCloseUndoGroup
UndoManager 1 (変更3) UndoManager 1 (変更1) UndoManager 2 (変更2) 上から取り出す
文字選択状態 カーソルの位置 テキスト以外の要素 要素をまたぐUndoG
気合い
あとはエディタに不 具合があったりして 大変だった
まだ不具合があると 思う ごめん。。。
UndoManagerはシンプルなスタッy registerUndo → undo()・redo(R 複数処理をまとめられるGroupins 勝手にいい感じにやってくれF
やめろ!な時 groupsByEvent = falsÄ begin・endGroupins beginをしわすれるとクラッシ _UITextUndoManagerを使わないとデフォルトと違う動X ResponderChain外への対Â UndoManagerは通知を飛ばしまくF 通知を見てUndoManagerをスタックする
もっと細かい コードは 書くよ!