使用 SwiftUI 創作 CRUD 紀錄App-學咒語!

chinger
海大 SwiftUI iOS / Flutter App 程式設計
4 min readJun 3, 2020

(1) App 操作的影片或 gif

(二)Github連結

(三)特製的 App 畫面截圖

(四)文字說明

繼續上次的哈利波特咒語,不過這次加了小巧思,之前上課看老師使用了 AVSpeechSynthesizer覺得很好玩,這次便用上了,點擊咒語的說明便可以聽到咒語的正確發音!而且是英式發音喔,讓你學到最正統的!

這次依舊是data的原因,SpellEditor那為了判斷哪一集又寫了一對一樣的程式🙁 而且search做出來了,卻在最後一步SpellList那不知如何判斷字串而宣告失敗,期末週後會再嘗試一下。

(五)重點程式碼說明

1.使用 onMove 調整資料的順序。

List{
Search(text: $searchText)
ForEach(spellData.spells){ (spell) in
NavigationLink(destination: SpellEditor(spellData: self.spellData, editSpell: spell)){
SpellRow(spell: spell)
}
}
.onMove { (indexSet, index) in
self.spellData.spells.move(fromOffsets: indexSet,
toOffset: index)
}
.onDelete{(IndexSet) in
self.spellData.spells.remove(atOffsets: IndexSet)

}

2.圖表加上動畫效果。

Rectangle()
.fill(LinearGradient(gradient: Gradient(colors: [Color.red,Color.orange,Color.yellow,Color.green,Color.blue,Color.purple]), startPoint: .top, endPoint: .bottom))
.frame(width: 25, height: self.height[index])
.animation(.linear(duration: 1))
.onAppear
{
self.height[index] = CGFloat(self.scoreCount[index]) * 10
}

3.利用 AVSpeechSynthesizer 講話。

.onTapGesture {
let utterance = AVSpeechUtterance(string: "\(episode1[self.episodenum].name)")
utterance.rate = 0.3
utterance.voice = AVSpeechSynthesisVoice(language: "en-GB")
let synthesizer = AVSpeechSynthesizer()
synthesizer.speak(utterance)
}

--

--