<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pinyu on Medium]]></title>
        <description><![CDATA[Stories by Pinyu on Medium]]></description>
        <link>https://medium.com/@annhuang_49926?source=rss-b8069b5e4cd2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rsfbdqxrQHt6QXMXHLXlpg@2x.jpeg</url>
            <title>Stories by Pinyu on Medium</title>
            <link>https://medium.com/@annhuang_49926?source=rss-b8069b5e4cd2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 02:04:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@annhuang_49926/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[音樂播放器MusicPlayer]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E9%9F%B3%E6%A8%82%E6%92%AD%E6%94%BE%E5%99%A8musicplayer-cb90fa71602e?source=rss-b8069b5e4cd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb90fa71602e</guid>
            <dc:creator><![CDATA[Pinyu]]></dc:creator>
            <pubDate>Wed, 10 Aug 2022 12:49:16 GMT</pubDate>
            <atom:updated>2022-08-10T12:52:50.785Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m0FMKuAYeg4A5xAyqyoP8A.jpeg" /></figure><p>主要功能：</p><ol><li>CABasicAnimation:實現圖片旋轉效果</li><li>播放/暫停/上一首/下一首</li><li>重複播放/隨機播放/UIAlertController</li><li>利用UISlider/addPeriodicTimeObserver來實現歌曲目前時間/剩餘時間/removeTimePeriodicTimeObserve刪除時間顯示</li></ol><blockquote><strong>CABasicAnimation</strong> 實現圖片旋轉效果</blockquote><p>連接想要旋轉圖片的outlet</p><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> coverImageView: UIImageView!</pre><p>獨立寫一個旋轉功能的function</p><pre><strong>func</strong>  rotate() {</pre><pre><strong>let</strong> animation = CABasicAnimation(keyPath: &quot;transform.rotation&quot;)</pre><pre>animation.fromValue = 0</pre><pre>animation.toValue = Double.pi*2</pre><pre>animation.duration = 5</pre><pre>animation.repeatCount = .infinity</pre><pre>coverImageView.layer.add(animation,forKey: <strong>nil</strong>)</pre><pre>}</pre><p>寫入在播放功能裡面</p><pre><strong>func</strong> playAndStop(mode:playMode,song Index:Int){</pre><pre><strong>switch</strong> mode{</pre><pre><strong>case</strong> .play :</pre><pre>isPlay = <strong>true</strong></pre><pre>startButton.setImage(UIImage(named: &quot;stop&quot;), for: .normal)</pre><pre>player.play()</pre><pre>rotate()</pre><pre><strong>case</strong> .stop:</pre><pre>isPlay = <strong>false</strong></pre><pre>startButton.setImage(UIImage(named: &quot;play&quot;), for: .normal)</pre><pre>player.pause()</pre><pre>coverImageView.layer.removeAllAnimations(</pre><pre>}</pre><pre>}<br></pre><p>另外要讓旋轉的圖片停止,我把它寫在停止播放功能裡面</p><pre>coverImageView.layer.removeAllAnimations</pre><blockquote><strong>重複播放/按隨機播放時同時使用UIAlert作為提醒：</strong></blockquote><p>＊重複播放：</p><p>宣告一個Bool變數,讓true和false決定按鈕的function和圖案的改變</p><pre><strong>var</strong> repeatOn = <strong>false</strong></pre><p>拉 <strong>IBAction</strong> repeatButtonPressed寫入repeatButton.SetImage的變化</p><pre><strong>@IBAction</strong> <strong>func</strong> repeatButtonPressed(_ sender: UIButton) {<br>//按鈕每次按一下musicIndex加一</pre><pre>musicIndex = musicIndex + 1</pre><pre><strong>if</strong> musicIndex == 1{</pre><pre>repeatButton.setImage(UIImage(systemName: &quot;repeat.1&quot;), for: .normal)</pre><pre>repeatOn = <strong>true</strong></pre><pre>}<strong>else</strong> {</pre><pre>repeatButton.setImage(UIImage(systemName: &quot;repeat&quot;), for: .normal)</pre><pre>}</pre><pre>}</pre><p>有開啟重複播放功能與否&gt;正常播完歌曲後&gt;由observe觀察歌曲放完後&gt;使用if-else判斷為重複播放或是正常下一首播放</p><pre>//notificationObeserve自動播放下一首</pre><pre><strong>fileprivate</strong> <strong>func</strong> notitficaitonMusicRepeat(){</pre><pre>NotificationCenter.default.addObserver(forName: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: <strong>nil</strong>, queue: .main) { _ <strong>in</strong></pre><pre><strong>if</strong> <strong>self</strong>.repeatOn == <strong>true</strong>{</pre><pre>//偵測 value 0/ timescalse 1 = 0 時</pre><pre><strong>let</strong> musicEndTime:CMTime = CMTimeMake(value: 0, timescale: 1)</pre><pre>print(&quot;musicEndTime\(musicEndTime)&quot;)</pre><pre>//seek從頭播放</pre><pre><strong>self</strong>.player.seek(to: musicEndTime)</pre><pre><strong>self</strong>.CDImageView.layer.removeAllAnimations()</pre><pre><strong>self</strong>.player.play()</pre><pre>}<strong>else</strong> <strong>if</strong> <strong>self</strong>.repeatOn == <strong>false</strong> {</pre><pre><strong>self</strong>.playNext()</pre><pre>}</pre><pre>}</pre><pre>}</pre><p>＊開啟/關閉隨機播放時，有UIAlert跳出提醒：</p><p>獨立寫出alertOn/alertOff的function</p><pre><strong>func</strong> alertOn(){</pre><pre><strong>let</strong> controller = UIAlertController(title: &quot;開啟循環播放&quot;, message: &quot;&quot;, preferredStyle: .alert)</pre><pre><strong>let</strong> action = UIAlertAction(title: &quot;ok&quot;, style: .default)</pre><pre>controller.addAction(action)</pre><pre>present(controller, animated: <strong>true</strong>)</pre><pre>}</pre><pre><strong>func</strong> alertOff(){</pre><pre><strong>let</strong> controller = UIAlertController(title: &quot;關閉循環播放&quot;, message: &quot;&quot;, preferredStyle: .alert)</pre><pre><strong>let</strong> action = UIAlertAction(title: &quot;ok&quot;, style: .default)</pre><pre>controller.addAction(action)</pre><pre>present(controller, animated: <strong>true</strong>)</pre><pre>}</pre><p>拉 <strong>IBAction </strong>shuffleButtonPressed ，宣告shuffelNumber = 0，作為setImage和alert的顯示</p><pre><strong>var</strong> shuffelNumber = 0</pre><pre><strong>@IBAction</strong> <strong>func</strong> shuffleButtonPressed(_ sender: UIButton) {</pre><pre>//按一下加一</pre><pre>shuffelNumber += 1</pre><pre>//shuffleBtn按一下之後數值變1開啟隨機播放</pre><pre><strong>if</strong> shuffelNumber == 1{</pre><pre>shuffleButton.setImage(UIImage(systemName: &quot;shuffle.circle.fill&quot;), for: .normal)</pre><pre>alertOn()</pre><pre>}<strong>else</strong>{</pre><pre>//或是原預設值 ＝ 0</pre><pre>shuffelNumber = 0</pre><pre>shuffleButton.setImage(UIImage(systemName: &quot;shuffle&quot;), for: .normal)</pre><pre>alertOff()</pre><pre>}</pre><pre>}</pre><p>開啟/關閉隨機開關&gt;在要撥下一首時&gt;以if-else判斷為隨機播放或正常順序播放</p><pre><strong>func</strong> playNext(){</pre><pre>//最多就3首歌index = 2</pre><pre><strong>if</strong> shuffelNumber == 1{</pre><pre>musicIndex = Int.random(in: 0...songsList.count-1)</pre><pre>//曲目內容要更新（歌名 歌手 歌曲）</pre><pre>playMusic(index: musicIndex)</pre><pre>addPeriodTimeObserver()</pre><pre>print(&quot;musicIndexShuffle:\(musicIndex)&quot;)</pre><pre>}<strong>else</strong>{</pre><pre><strong>if</strong>  musicIndex &lt; 2 {</pre><pre>musicIndex += 1</pre><pre>playMusic(index: musicIndex)</pre><pre>playAndStop(mode: .play, song: musicIndex)</pre><pre>}<strong>else</strong>{</pre><pre>musicIndex = 0</pre><pre>playMusic(index: musicIndex)</pre><pre>playAndStop(mode: .play, song: musicIndex)</pre><pre>}</pre><pre>}</pre><pre>}</pre><blockquote><strong>利用UISlider/addPeriodicTimeObserver來實現歌曲目前時間/剩餘時間</strong></blockquote><pre><strong>var</strong> timeObserveToken:<strong>Any</strong>?</pre><pre>//暫存到其他func使用</pre><pre><strong>var</strong> songCurrentTime:Float!</pre><pre><strong>var</strong> songTotalTime:Float!</pre><pre>//暫存func裡的變數</pre><pre><strong>var</strong> timeConverter:String!</pre><p>拉三個outlet代表：</p><p>歌曲播放開始的時間timeStartingLabel</p><p>剩餘播放顯示時間timeTotalLabel: UILabel!</p><p>使用UISlider顯示目前歌曲的進度songSlider: UISlider!</p><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> timeStartingLabel: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> timeTotalLabel: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> songSlider: UISlider!</pre><p>顯示歌曲時間的addPeriodicTimeObserver，這邊比較容易搞混的是型別的轉換。</p><pre><strong>func</strong> addPeriodTimeObserver(){</pre><pre>//CMTimeScale一個整數時間的計時尺度</pre><pre>//每0.5更新一次</pre><pre><strong>let</strong> timeScale = CMTimeScale(NSEC_PER_SEC)</pre><pre><strong>let</strong> time = CMTime(seconds: 0.5, preferredTimescale: timeScale)</pre><pre>timeObserveToken = player.addPeriodicTimeObserver(forInterval:time,  queue:.main){ [<strong>weak</strong> <strong>self</strong>] time <strong>in</strong></pre><pre>//取現在播放時間</pre><pre><strong>let</strong> songCurrent = <strong>self</strong>?.player.currentTime().seconds//double</pre><pre><strong>self</strong>!.songCurrentTime = Float(songCurrent!)</pre><pre>//取總播放時間</pre><pre><strong>let</strong> duration = <strong>self</strong>?.player.currentItem?.asset.duration</pre><pre><strong>let</strong> songTotal = CMTimeGetSeconds(duration!)</pre><pre><strong>self</strong>!.songTotalTime = Float(songTotal)<br></pre><pre>//UI:songSlider.value</pre><pre><strong>let</strong> currentTotal:Float = Float(songCurrent!/songTotal)</pre><pre><strong>self</strong>?.songSlider.value = currentTotal</pre><pre>//updateUI</pre><pre>updateUI()</pre><pre>}</pre><p>使用timeConvert轉成timeStartingLabel and timeTotalLabel的格式</p><pre><strong>func</strong> timeConverter(_ timeInSecond: Float) -&gt; String {</pre><pre><strong>let</strong> minute = Int(timeInSecond) / 60</pre><pre><strong>let</strong> second = Int(timeInSecond) % 60</pre><pre><strong>return</strong> second &lt; 10 ? &quot;\(minute):0\(second)&quot; : &quot;\(minute):\(second)</pre><pre>}</pre><p>刪除時間顯示removeTimePeriodicTimeObserve：</p><pre>//參照appleDoucment寫法</pre><pre>//刪除顯示整首歌時間的func(用在musucPlay,viewWillDisapper)</pre><pre><strong>func</strong> removeTimePeriodicTimeObserve(){</pre><pre><strong>if</strong> <strong>let</strong> timeObserveToken = timeObserveToken {</pre><pre>player.removeTimeObserver(timeObserveToken)</pre><pre><strong>self</strong>.timeObserveToken = <strong>nil</strong></pre><pre>}</pre><pre>}</pre><p>記得要update一下UI顯示：</p><pre>//UpdateUI:在跳下一首或上一首時才會更新整首歌的顯示時間</pre><pre><strong>func</strong> updateUI(){</pre><pre><strong>if</strong> songCurrentTime == songCurrentTime{</pre><pre>//UI:timeStartingLabel.text</pre><pre><strong>self</strong>.timeStartingLabel.text = timeConverter(totalsecond: songCurrentTime)</pre><pre>//UI:timeTotalLabel.text</pre><pre><strong>self</strong>.timeTotalLabel.text = timeConverter(totalsecond: songTotalTime - songCurrentTime)</pre><pre>songSlider.value = songCurrentTime/songTotalTime</pre><pre>}<strong>else</strong>{</pre><pre>print(&quot;false area&quot;)</pre><pre>}</pre><pre>}</pre><blockquote><strong>Vedio Showing:</strong></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Frde3rf&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Frde3rf&amp;image=https%3A%2F%2Fcdn-cf-east.streamable.com%2Fimage%2Frde3rf.jpg%3FExpires%3D1660292880%26Signature%3DVM5pHYagCiUW3HseKR0nQmopgUjZy7P1vDc1bV5shUTVagGN2XfYBH7vzCGu1j4XEnxNp9iVZKY1KP2oO9ZK1oIV4M4NFqqLyZusZLQdYNYVq%7Ex0A1hrAW7N7nca6a-hlXp9-q-qtePgJXrWfcHGZrGvnjLkJ5HDYCL5qWWnJS2TndzmYKKa379X4D2b0YcaVPsb%7E0slt-frIoCuzN%7EliTbWyO5hssL7jHWrWt4KxdAo0cG4TqQ6rC6QBpzQBohGdpi6a6xU94Msdep8roy3S9VXt5tFvviPfnIkZUNyMchze9-kBqev7eqr0VoPKGcmKhjEfxx%7E8Ji69NVf3XGGsg__%26Key-Pair-Id%3DAPKAIEYUVEN4EVB2OKEQ&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="332" height="718" frameborder="0" scrolling="no"><a href="https://medium.com/media/b71f1dfdff378b8130770410cb076c4d/href">https://medium.com/media/b71f1dfdff378b8130770410cb076c4d/href</a></iframe><blockquote><strong>GitHub:</strong></blockquote><p>無法成功上傳</p><blockquote><strong>Reference:</strong></blockquote><ul><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/swift-%E7%B7%B4%E7%BF%92-music-app-2-avplayer-fa6f6d37c94d">[Swift]Music App #2 AVPlayer</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E5%88%A9%E7%94%A8-viewdidload-%E9%BB%9E%E4%B8%80%E9%A6%96%E6%AD%8C-%E6%92%AD%E6%94%BE%E4%B8%80%E6%AC%A1pl-bfe59e9e22c">利用 AVPlayer 播放音樂音效</a></li><li><a href="https://jjeremy-xue.medium.com/swift-%E8%AA%AA%E8%AA%AA-cabasicanimation-9be31ee3eae0">Swift — 說說 動畫（CABasicAnimation）</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/swift-%E5%AF%A6%E7%8F%BE%E7%84%A1%E6%AD%A2%E7%9B%A1-360-%E5%BA%A6%E6%97%8B%E8%BD%89%E5%8B%95%E7%95%AB%E7%9A%84%E4%B8%89%E5%80%8B%E6%96%B9%E6%B3%95-9599eb9ab36a">Swift 實現無止盡 360 度旋轉動畫的三個方法</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E5%88%A9%E7%94%A8-viewdidload-%E9%BB%9E%E4%B8%80%E9%A6%96%E6%AD%8C-%E6%92%AD%E6%94%BE%E4%B8%80%E6%AC%A1pl-bfe59e9e22c">利用 AVPlayer 播放音樂音效</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/94-%E6%A8%A1%E4%BB%BF-ios-%E7%9A%84-music-app-%E8%A3%BD%E4%BD%9C%E6%83%85%E6%AD%8C%E9%BB%9E%E5%94%B1%E6%A9%9F-acacd22d8928">#94 模仿 iOS 的 Music App 製作情歌點唱機(音樂播放器)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb90fa71602e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E9%9F%B3%E6%A8%82%E6%92%AD%E6%94%BE%E5%99%A8musicplayer-cb90fa71602e">音樂播放器MusicPlayer</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[『龜記飲品Guiji 』-3 DELETE]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E9%BE%9C%E8%A8%98%E9%A3%B2%E5%93%81guiji-3-delete-3f646a60568c?source=rss-b8069b5e4cd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f646a60568c</guid>
            <dc:creator><![CDATA[Pinyu]]></dc:creator>
            <pubDate>Sat, 07 May 2022 12:13:23 GMT</pubDate>
            <atom:updated>2022-05-16T12:44:11.981Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zVhAX5U0mSxs-XLpukdJIA.jpeg" /></figure><blockquote>cartTableViewController:</blockquote><p>1 刪除購物車（httpMethod:Delete)</p><p>2.計算總金額及總杯數。</p><p>3.orderIndicator:在未載入畫面時以indicator動畫取代。</p><p><strong>刪除購物車資料：</strong></p><p>先以HTTPMthod：GET先下載airtable的order資料夾的資料：</p><pre><strong>func</strong> fetchOrder(){</pre><pre><strong>let</strong> urlStr = URL(string: &quot;https://api.airtable.com/v0/apptv4BpzWCodIRFa/order&quot;)!</pre><pre><strong>var</strong> request = URLRequest(url: urlStr)</pre><pre>request.setValue(&quot;Bearer keyFJVtTa4TlSkKFJ&quot;, forHTTPHeaderField: &quot;Authorization&quot;)</pre><pre>request.setValue(&quot;application/json&quot;, forHTTPHeaderField: &quot;Content-Type&quot;)</pre><pre>URLSession.shared.dataTask(with: request) { data, response, error <strong>in</strong></pre><pre><strong>do</strong>{</pre><pre><strong>let</strong> decoder = JSONDecoder()</pre><pre><strong>if</strong> <strong>let</strong> data = data {</pre><pre><strong>self</strong>.orderResponse = <strong>try</strong>? decoder.decode(OrderResponse.<strong>self</strong>, from: data)</pre><pre>DispatchQueue.main.async { [<strong>self</strong>] <strong>in</strong></pre><pre><strong>self</strong>.orderRecords = <strong>self</strong>.orderResponse!.records</pre><pre><strong>self</strong>.tableView.reloadData()<br></pre><pre>//orderIndicator part</pre><pre>totalView.isHidden = <strong>false</strong></pre><pre>orderIndicator.stopAnimating()</pre><pre>orderIndicator.isHidden = <strong>true</strong></pre><pre>}</pre><pre>}}<strong>catch</strong>{</pre><pre>print(&quot;fetch error&quot;)</pre><pre>}</pre><pre>}.resume()</pre><pre>}</pre><p>接著在以httpMethod:Delete搭配swipeToDelete來刪除tableView的資料：</p><pre><strong>override</strong> <strong>func</strong> tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {</pre><pre><strong>if</strong> editingStyle == .delete{</pre><pre>//根據id來做刪除</pre><pre><strong>let</strong> urlStr = URL(string: &quot;https://api.airtable.com/v0/apptv4BpzWCodIRFa/order&quot; + &quot;/&quot; + (<strong>self</strong>.orderResponse?.records[indexPath.row].id)!)!</pre><pre><strong>var</strong> request = URLRequest(url: urlStr)</pre><pre>request.httpMethod = &quot;DELETE&quot;</pre><pre>request.setValue(&quot;Bearer keyFJVtTa4TlSkKFJ&quot;, forHTTPHeaderField: &quot;Authorization&quot;)</pre><pre><strong>if</strong> editingStyle == .delete {</pre><pre>URLSession.shared.dataTask(with: request) { data, response, error <strong>in</strong></pre><pre><strong>guard</strong> <strong>let</strong> response = response <strong>as</strong>? HTTPURLResponse <strong>else</strong>{<strong>return</strong>}</pre><pre>print(response.statusCode) //feedBack = 200 成功</pre><pre>DispatchQueue.main.async {</pre><pre>//刪除tableview上的row</pre><pre>tableView.deleteRows(at: [indexPath], with: .fade)</pre><pre><strong>self</strong>.logger.log(&quot;deleteTheRow&quot;)</pre><pre>//因刪除row重新計算總金額跟總杯數</pre><pre><strong>self</strong>.totalCounting()</pre><pre>//重新update airtable Order資料</pre><pre><strong>self</strong>.fetchOrder()</pre><pre><strong>self</strong>.logger.log(&quot;fetchOrderData&quot;)</pre><pre><strong>self</strong>.orderRecords.remove(at: indexPath.row)</pre><pre>}</pre><pre>}.resume()</pre><pre>//刪除tableview上資料</pre><pre><strong>self</strong>.orderRecords.remove(at: indexPath.row)</pre><pre><strong>self</strong>.logger.log(&quot;removeTheRecord&quot;)</pre><pre>}</pre><p>因為delete個別得row需要以ＩＤ來辨識，所以網址寫法如下：</p><pre><strong>let</strong> urlStr = URL(string: &quot;https://api.airtable.com/v0/apptv4BpzWCodIRFa/order&quot; + &quot;/&quot; + (<strong>self</strong>.orderResponse?.records[indexPath.row].id)!)!</pre><p>response as? httpResponse來判斷，是否下載成功：</p><pre><strong>guard</strong> <strong>let</strong> response = response <strong>as</strong>? HTTPURLResponse <strong>else</strong>{<strong>return</strong>}</pre><pre>print(response.statusCode) //feedBack = 200 成功</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*zu547pkZJdKTDBjqGzcAwQ.png" /><figcaption>console裡顯示status200代表資料下載到tableView成功</figcaption></figure><p><strong>比較特別的是在deleteRow產生crash:</strong></p><p>如果按照以下寫法，<strong>在刪除row時就會因為row的數量和數據的數量不相等,所以產生了crash</strong>。</p><pre>DispatchQueue.main.async {</pre><pre>//刪除tableview上資料<br><strong>self</strong>.orderRecords.remove(at: indexPath.row)</pre><pre>//刪除tableview上的row<br>tableView.deleteRows(at: [indexPath], with: .fade)</pre><pre>}</pre><pre>}.resume()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TA3xHz-E7AHKe7oDHEf9EQ.png" /><figcaption>tableView insert and delete rows產生crash</figcaption></figure><p>但若以下面寫法跑logger,就會發現，先刪除row上的資料，再deleteRow，就不會造成crash。</p><pre>DispatchQueue.main.async {</pre><pre>//刪除tableview上的row</pre><pre>tableView.deleteRows(at: [indexPath], with: .fade)</pre><pre><strong>self</strong>.logger.log(&quot;deleteTheRow&quot;)</pre><pre>//因刪除row重新計算總金額跟總杯數</pre><pre><strong>self</strong>.totalCounting()</pre><pre>//重新update airtable Order資料</pre><pre><strong>self</strong>.fetchOrder()</pre><pre><strong>self</strong>.logger.log(&quot;fetchOrderData&quot;)</pre><pre><strong>self</strong>.orderRecords.remove(at: indexPath.row)</pre><pre>}</pre><pre>}.resume()</pre><pre>//刪除tableview上資料</pre><pre><strong>self</strong>.orderRecords.remove(at: indexPath.row)</pre><pre><strong>self</strong>.logger.log(&quot;removeTheRecord&quot;)</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tjw_ylXpDIncKSHjhFGktw.png" /></figure><p>Reference:</p><ul><li><a href="https://developer.apple.com/forums/thread/88190">iOS 11 UITableView deleteRows crash</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E5%88%A9%E7%94%A8-logger-%E5%8D%B0%E5%87%BA%E5%8C%85%E5%90%AB%E6%99%82%E9%96%93%E7%9A%84-debug-%E8%A8%8A%E6%81%AF-f5018134d61f">利用 Logger 印出包含時間的 debug 訊息</a></li></ul><p><strong>計算總金額及總杯數:</strong></p><ul><li>在UI的部分，加入一個view在加入總金額跟總杯數的label並連接outlet。</li></ul><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> cartTotalPrice: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> cartTotalCups: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> totalView: UIView!</pre><ul><li>寫一個func,因如果在載入或刪除tableView上的飲料資訊時，都需要重新計算一次總金額跟杯數。</li></ul><pre><strong>func</strong> totalCounting(){</pre><pre>//計算totalPrice及總杯數</pre><pre>cartTotalCups.text = &quot;\(orderRecords.count)&quot; + &quot;杯&quot;</pre><pre><strong>var</strong> total = 0</pre><pre><strong>for</strong> i <strong>in</strong> orderRecords{</pre><pre>total += i.fields.subtotal</pre><pre>cartTotalPrice.text = &quot;\(total)&quot; + &quot;元&quot;</pre><pre>}</pre><pre>}</pre><p><strong>orderIndicator:</strong></p><p>連接outlet:</p><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> orderIndicator: UIActivityIndicatorView!</pre><p>在viewDidLoad顯示畫面時，開始indicator的animation，及把顯示總金額的totalView隱藏。</p><pre>orderIndicator.startAnimating()</pre><pre>totalView.isHidden = <strong>true</strong></pre><p>當成功串接資料及UITableView顯示後，在停止及隱藏orderIndicator的animation及顯示出totalView。</p><pre>totalView.isHidden = <strong>false</strong></pre><pre>orderIndicator.stopAnimating()</pre><pre>orderIndicator.isHidden = <strong>true</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*iVlx6pglx7IFL0aSZj8QuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CgQqpnZoSiEIEBRdgjhnwA.png" /><figcaption>左：因為以tableView下載畫面尚未顯示出時，只顯示出view的總金額。右：希望未載入tableView畫面時以orderindicator動畫取代。</figcaption></figure><blockquote>GuijiVedio:</blockquote><p><a href="https://streamable.com/0uc492">Simulator Screen Recording - iPhone 12 - 2022-05-03 at 01.38.28</a></p><blockquote>Github:</blockquote><p><a href="https://github.com/annhuang777/GuijiDrinkingApp">GitHub - annhuang777/GuijiDrinkingApp: API串接POST/GET/DELETE（airtable data Base)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f646a60568c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E9%BE%9C%E8%A8%98%E9%A3%B2%E5%93%81guiji-3-delete-3f646a60568c">『龜記飲品Guiji 』-3 DELETE</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[『龜記飲品Guiji』-2 GET/POST]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E9%BE%9C%E8%A8%98%E9%A3%B2%E5%93%81guiji-2-get-post-edf48454ae04?source=rss-b8069b5e4cd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/edf48454ae04</guid>
            <dc:creator><![CDATA[Pinyu]]></dc:creator>
            <pubDate>Sat, 07 May 2022 12:12:09 GMT</pubDate>
            <atom:updated>2022-05-16T12:46:42.094Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zVhAX5U0mSxs-XLpukdJIA.jpeg" /></figure><blockquote>Storyboard構成 :</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O7xYJIp8-ndvaFOOms4UNw.png" /></figure><blockquote>menuViewController：</blockquote><p>1.airtable部分：龜記飲料主要分成四種系列(menu1~menu4)及order資料夾。</p><p>2.Banner輪播(collectionViewController and Timer)</p><p>3.airtable(後台資料儲存）抓所有飲料資料（httpMethod:Get)。</p><p>4.從UISegmentedController搭配containerView切換系列飲料。</p><p><strong>前置：從申請airtable帳號，輸入飲料資訊，到account取得apiKey的詳細步驟可參考</strong>。</p><p><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E4%B8%B2%E6%8E%A5-airtable%E7%9A%84-api-%E9%96%8B%E7%99%BC-ios-app-5e5c86c8ca7d">串接 Airtable的 API 開發 iOS App</a></p><p><strong>GET/POST/DELETE/PUT說明：</strong></p><ul><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E4%BD%BF%E7%94%A8-urlsession-%E4%B8%B2%E6%8E%A5-http-get-post-delete-put-api-%E4%BB%A5-reqres-api-%E7%82%BA%E4%BE%8B-f977ec876c33">使用 URLSession 串接 REST API，練習 http get，post，delete，put，以 Reqres API 為例</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E6%A8%A1%E4%BB%BF-apple-%E5%AE%98%E6%96%B9%E7%AF%84%E4%BE%8B%E4%B8%B2%E6%8E%A5-json-api-%E5%AE%9A%E7%BE%A9-function-%E5%9E%8B%E5%88%A5%E7%9A%84-completion-%E5%8F%83%E6%95%B8-%E4%BD%BF%E7%94%A8-result-type-9b058c77df5d">模仿 Apple 官方範例串接 JSON API，定義 function 型別的 completion 參數 &amp; 使用 Result type</a></li></ul><p><strong>Banner Reference:</strong></p><ul><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E7%94%A8-flow-layout-%E7%9A%84-collection-view-%E5%AF%A6%E7%8F%BE%E6%B0%B4%E5%B9%B3%E6%BB%91%E5%8B%95%E7%9A%84%E5%88%86%E9%A0%81%E7%95%AB%E9%9D%A2-328a24c9b6b5">用 flow layout 的 collection view 實現水平滑動的分頁畫面</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E5%88%A9%E7%94%A8-flow-layout-%E7%9A%84-collection-view-%E8%A3%BD%E4%BD%9C%E7%85%A7%E7%89%87%E7%89%86-e31dad55a7ac">利用 flow layout 的 collection view 製作照片牆</a></li></ul><blockquote>GetOrderViewController：</blockquote><p>1.IBSegueAction:從上一頁（menuVC)傳送飲料資訊到GetOrderVC</p><p>2.POST詳細資料到airTable(httpMethod:POST)。</p><p>3.UIAlertController檢視如果點購人空白跳出警告。</p><p>4.加入animation的expandable List。</p><p>＊在上傳資料到airTable前，如果textField是空白會產生alert；定購完成後也會有一個alert提示已訂購成功<strong>，卡住比較久地方是沒有帶入record中的id和createdTime到JSONDecode裡（下列粗體字部份）：</strong></p><pre><strong>if</strong> nameTextField.text == &quot;&quot;{</pre><pre><strong>let</strong> controller = UIAlertController(title: &quot;訂購人空白&quot;, message: &quot;請填寫訂購大名&quot;, preferredStyle: .alert)</pre><pre><strong>let</strong> action = UIAlertAction(title: &quot;OK&quot;, style: .default)</pre><pre>controller.addAction(action)</pre><pre>present(controller, animated: <strong>true</strong>)</pre><pre>}<strong>else</strong>{</pre><pre><strong>let</strong> orderName = nameTextField.text ?? &quot;&quot;</pre><pre><strong>let</strong> drinkName = productItem</pre><pre><strong>let</strong> ice = iceBtn.titleLabel?.text</pre><pre><strong>let</strong> sugar = sugarBTn.titleLabel?.text</pre><pre><strong>let</strong> topping = toppingBtn.titleLabel?.text</pre><pre><strong>let</strong> quantity = Int(amountLabel.text!)</pre><pre><strong>let</strong> subtatol = productPrice + toppingPrice</pre><pre><strong>let</strong> urlStr = URL(string: &quot;https://api.airtable.com/v0/apptv4BpzWCodIRFa/order&quot;)!</pre><pre><strong>var</strong> request = URLRequest(url: urlStr)</pre><pre>request.httpMethod = &quot;POST&quot;</pre><pre>request.setValue(&quot;Bearer keyFJVtTa4TlSkKFJ&quot;, forHTTPHeaderField: &quot;Authorization&quot;)</pre><pre>request.setValue(&quot;application/json&quot;, forHTTPHeaderField: &quot;Content-Type&quot;)</pre><pre><strong>let orderFields = OrderFields(orderName: orderName, ice: ice ?? &quot;&quot;, topping: topping ?? &quot;&quot;, sugar: sugar ?? &quot;&quot;, quantity: quantity!, subtotal: subtatol, drinkName: drinkName)</strong></pre><pre><strong>print(orderFields)<br></strong></pre><pre><strong>let records = OrderResponse.OrderRecords(id:nil, createdTime: nil, fields: orderFields)</strong></pre><pre><strong>let</strong> encoder = JSONEncoder()</pre><pre><strong>let</strong> data = <strong>try</strong>? encoder.encode(records)</pre><pre>request.httpBody = data</pre><pre>URLSession.shared.uploadTask(with: request, from: data){data,response,error <strong>in</strong></pre><pre><strong>if</strong> <strong>let</strong> data = data ,<strong>let</strong> content = String(data:data, encoding:.utf8){</pre><pre>print(&quot;check&quot;,content)</pre><pre>}<strong>else</strong>{</pre><pre>print(&quot;failed&quot;)</pre><pre>}</pre><pre>}.resume()</pre><pre>//訂購成功alert</pre><pre><strong>let</strong> controller = UIAlertController(title: &quot;訂購成功&quot;, message:&quot;a nice Choise&quot; , preferredStyle:.alert)</pre><pre><strong>let</strong> action =  UIAlertAction(title:&quot;OK&quot;, style: .default)</pre><pre>controller.addAction(action)</pre><pre>present(controller, animated: <strong>true</strong>, completion: <strong>nil</strong>)</pre><pre>//完成訂購後</pre><pre>//addBtn 不能再按且變成灰色</pre><pre>addBtn.isEnabled = <strong>false</strong></pre><pre>addBtn.backgroundColor = .gray</pre><pre>//textField從有名字變成空白</pre><pre>nameTextField.text = &quot;&quot;</pre><pre>}</pre><pre>}</pre><ul><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E5%88%A9%E7%94%A8-ibsegueaction-%E5%82%B3%E8%B3%87%E6%96%99%E5%88%B0%E4%B8%8B%E5%80%8B%E9%A0%81%E9%9D%A2%E7%9A%84-controller-ios-13-%E6%96%B0%E5%8A%9F%E8%83%BD-50813ba3822">利用 IBSegueAction 傳資料到下個頁面的 controller — iOS 13 新功能</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E9%A1%AF%E7%A4%BA%E8%AD%A6%E5%91%8A%E8%A8%8A%E6%81%AF%E5%92%8C%E9%81%B8%E5%96%AE%E7%9A%84-uialertcontroller-a7548b606eea">顯示警告訊息和選單的 UIAlertController</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FrV3lGy1xdv4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrV3lGy1xdv4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FrV3lGy1xdv4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d0dc07c144e32b927bca02592bad6db/href">https://medium.com/media/6d0dc07c144e32b927bca02592bad6db/href</a></iframe><blockquote>Github:</blockquote><p><a href="https://github.com/annhuang777/GuijiDrinkingApp">GitHub - annhuang777/GuijiDrinkingApp: API串接POST/GET/DELETE（airtable data Base)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edf48454ae04" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E9%BE%9C%E8%A8%98%E9%A3%B2%E5%93%81guiji-2-get-post-edf48454ae04">『龜記飲品Guiji』-2 GET/POST</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[『龜記飲品Guiji』-1 UIAnimate動畫]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E9%BE%9C%E8%A8%98%E9%A3%B2%E5%93%81guiji-1-uianimate%E5%8B%95%E7%95%AB-f2f31520498?source=rss-b8069b5e4cd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2f31520498</guid>
            <dc:creator><![CDATA[Pinyu]]></dc:creator>
            <pubDate>Sat, 07 May 2022 12:11:23 GMT</pubDate>
            <atom:updated>2022-05-16T12:45:17.753Z</atom:updated>
            <content:encoded><![CDATA[<p>『龜記飲品Guiji』-1 UIAnimate動畫</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W5oHOGIYEFqtRXx_2oDRWw.jpeg" /></figure><blockquote>homePageViewController主要組成：</blockquote><ol><li>手勢Gesture : tapGestureReconizer</li><li>動畫:Core Animation:UIView.animate</li></ol><blockquote>手勢搭配動畫顯示說明：</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UIlM7TIdivcHImDoC1MGvg.jpeg" /><figcaption>左：image1 右：image2 ,button:image3,orderLabel</figcaption></figure><p>經TapGesture點擊，第一張圖(image1)面淡出，接著秀出第二張圖片(image2)及訂購的button(image3),接著提示點餐的orderLabel也以彈簧動畫（springAnimation)方式由上到下顯示。</p><blockquote>實作步驟：</blockquote><p>首先先把storybord顯示的圖片設定好autolayout，除了因orderLabel顯示方向是由上至下的彈簧動畫不用設定autolayout外，再拉outlet到homePageViewController.</p><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> firstImageView: UIImageView!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> secondImageview: UIImageView!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> orderLabel: UILabel!</pre><p>接著宣告UITapGrestureReconizer:</p><pre><strong>let</strong> gestureRecognizer = UITapGestureRecognizer()</pre><p>numberOfTapsRequired設為1，表示點一下動畫開始</p><pre>gestureRecognizer.numberOfTapsRequired = 1</pre><p>gestureRecognizer.addTarget帶入@objc Func TapToChange觸發動畫的樣式。另外第一個淡出的Image1，以addGestureRecognizer加入到gestureRecognizer，在點一下之後，第一個動畫才會有淡出的效果。</p><pre>gestureRecognizer.addTarget(<strong>self</strong>, action: <strong>#selector</strong>(TapToChange(gesture:)))</pre><pre>firstImageView.addGestureRecognizer(gestureRecognizer)</pre><p>Func Animate說明:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6PbqNBd_eAUxC37SwOWBkw.png" /><figcaption>withDuration:整個動畫的時間以秒顯示，animation這個closureBlock：淡出的image1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N_c0gIb5OO1cix3oYNZ-3Q.png" /></figure><p>duration:整個動畫的顯示的時間。</p><p>delay:在畫面載入時要delay多久開始動畫，若為０就代表直接顯示動畫。</p><p>springDamping（彈簧動畫的彈動大小）: damping值介於0~1之間，若阻力越小為０則彈動較大，阻力越大為1則彈動較小。</p><p>springVelocity(彈簧動畫的速度）：值大速度快。</p><p>options:顯示動畫的方式。</p><p>animation:顯示第一個動畫。</p><p>completion:可連接著顯示第二個動畫或是nil完成動畫。</p><pre><strong>@objc</strong> <strong>func</strong> TapToChange(gesture:UITapGestureRecognizer){<br></pre><pre>UIView.animate(withDuration: 4, delay: 0, options: .curveEaseOut) {</pre><pre><strong>self</strong>.firstImageView.alpha = 0<br></pre><pre>} completion: { (_) <strong>in<br></strong></pre><pre>UIView.animate(withDuration: 3, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: .curveEaseIn) {</pre><pre><strong>self</strong>.orderLabel.isHidden = <strong>false</strong></pre><pre><strong>self</strong>.orderLabel.transform = CGAffineTransform(translationX: 0, y:80)</pre><pre>}</pre><pre>}</pre><p>firstImageView在使用手勢之下要設為true，在按下之後才會出現動畫</p><pre>firstImageView.isUserInteractionEnabled = <strong>true</strong></pre><blockquote>影片：</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Fowtsja&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Fowtsja&amp;image=https%3A%2F%2Fcdn-cf-east.streamable.com%2Fimage%2Fowtsja.jpg%3FExpires%3D1648902000%26Signature%3DMMDKQ3YIBM98nVxhCQCHrLurMpw4wIZv0cnI7OS3R7-hQYBVVwHX3N7PvcEbecIV6ibEdbvWtWT2lVZCBdU8GdqArRQkDj3scjBb3wG9CH2fBom02qUcfPZLgBeZXKvlOJXN6drtDvk3hb0g035vgDBylj9XdIBQy%7E9JVuOS3bOgDF-%7EQ-Du%7Epb1iCJorfiLA6Nrr4FyCxJYc-z6kv6sgdAZimxyNMJCXt%7EDmorrE3dNPb9ps4gOTsCFgzqjBBBHasZZuNaNWHkJAeoLcMeT7C-Zl1We-Nw3hpWWkmQJJn6v6xqrV%7E-fKO8X5hPaBE1jvTNzh-214qRvyiegQhVgZg__%26Key-Pair-Id%3DAPKAIEYUVEN4EVB2OKEQ&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="332" height="718" frameborder="0" scrolling="no"><a href="https://medium.com/media/df6d7ef2f24d7c4d0508b706c35c3fc5/href">https://medium.com/media/df6d7ef2f24d7c4d0508b706c35c3fc5/href</a></iframe><blockquote>心得：</blockquote><p>因為這次要做得效果比較簡單，所以使用UIView.animate，但其實還有其他</p><p>UIpropertyAnimation等，可以做出更生動更複雜的動畫，都值得再研究。</p><blockquote>Github:</blockquote><p><a href="https://github.com/annhuang777/GuijiDrinkingApp">GitHub - annhuang777/GuijiDrinkingApp: API串接POST/GET/DELETE（airtable data Base)</a></p><p><em>Reference:</em></p><blockquote>Gesture:</blockquote><p><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E9%96%8B%E7%99%BC-ios-app-%E7%9A%84-gesture-%E6%89%8B%E5%8B%A2%E5%8A%9F%E8%83%BD-uikit-%E7%89%88%E6%9C%AC-f6cb95075705">開發 iOS App 的 Gesture (手勢)功能 — UIKit 版本</a></p><blockquote>UIAnimate:</blockquote><p><a href="https://ithelp.ithome.com.tw/articles/10225732">https://ithelp.ithome.com.tw/articles/10225732</a></p><p>其他製作動畫參考：</p><blockquote>CoreAnimation理論：</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F93bfh3GK79s%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D93bfh3GK79s&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F93bfh3GK79s%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba0e619d335effd5294a24342a8865ee/href">https://medium.com/media/ba0e619d335effd5294a24342a8865ee/href</a></iframe><p><a href="https://github.com/jrasmusson/swift-arcade/tree/master/Animation/CoreAnimation/Intro">swift-arcade/Animation/CoreAnimation/Intro at master · jrasmusson/swift-arcade</a></p><blockquote>UIpropertyAnimation:</blockquote><p><a href="https://www.appcoda.com.tw/interactive-animation-uiviewpropertyanimator/">利用 UIViewPropertyAnimator 製作進階動畫　為 App 增強使用者體驗！</a></p><blockquote>CABasicAnimation基本的動畫顯示：</blockquote><p><a href="https://ithelp.ithome.com.tw/articles/10226078">https://ithelp.ithome.com.tw/articles/10226078</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2f31520498" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E9%BE%9C%E8%A8%98%E9%A3%B2%E5%93%81guiji-1-uianimate%E5%8B%95%E7%95%AB-f2f31520498">『龜記飲品Guiji』-1 UIAnimate動畫</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[模仿MeditationApp]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E6%A8%A1%E4%BB%BFmeditationapp-10cb1fab1b24?source=rss-b8069b5e4cd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/10cb1fab1b24</guid>
            <dc:creator><![CDATA[Pinyu]]></dc:creator>
            <pubDate>Wed, 22 Sep 2021 14:47:10 GMT</pubDate>
            <atom:updated>2021-11-09T17:24:03.422Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BaXdZKQiUizJO-vSRWGtpg.jpeg" /></figure><blockquote>作品發想：</blockquote><p>因為下載了一款ME.app，覺得這個app介面實在做得太美了，所以決定模仿一下這個app，基本功能都已經做出來，也做了一些修改，但還是不及原本app有美感。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*a6IcK-owFmHLvGdvbZ21qQ.png" /></figure><h3>User Page:</h3><ol><li>使用影片動畫當背景畫面：</li></ol><p>會使用到AVFoundation裡的播放影片功能，所以一開始要先import：</p><pre><strong>import</strong> AVFoundation</pre><p>因為把影片當背景，不間斷，所以在ViewController裡宣告AVPlayerLooper：</p><pre><strong>var</strong> looper:AVPlayerLooper?</pre><p>拉所有畫面中的Outlet，特別增加一個VedioView:UIView來當背景畫面的View：</p><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> passwordTextField: UITextField!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> accountTextField: UITextField!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> passWrodLabel: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> accountLabel: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> enterButton: UIButton!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> vedioView: UIView!</pre><p>為了避免程式看起來太亂，另外寫了一個Func內容是重播播放影片功能：</p><pre><strong>func</strong> setUpVedio(){</pre><pre>//帶入存在資料夾的影片</pre><pre><strong>let</strong> path = URL(fileURLWithPath: Bundle.main.path(forResource: &quot;wave&quot;, ofType: &quot;mov&quot;)!)</pre><pre>//利用重複播放功能，讓背景沒有停止的畫面</pre><pre><strong>let</strong> player = AVQueuePlayer()</pre><pre><strong>let</strong> item = AVPlayerItem(url: path)</pre><pre>looper = AVPlayerLooper(player: player, templateItem: item)</pre><pre>//AVPlayerLayer管理影像的輸出</pre><pre><strong>let</strong> newLayer = AVPlayerLayer(player: player)</pre><pre>//增加一個view讓vedio的大小跟view的大小相同</pre><pre>newLayer.frame = <strong>self</strong>.vedioView.frame</pre><pre>//</pre><pre><strong>self</strong>.vedioView.layer.addSublayer(newLayer)</pre><pre>//讓vdeio,AspectFill in View</pre><pre>newLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill</pre><pre>player.play()</pre><pre>}</pre><p>之後再把影片播放的Func，放在viewDidLoad裡，特別是因為這樣在拉好的UIControl無法顯示在背景上，所以又使用addSubView功能：</p><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()<br></pre><pre>//加入vedio後UIControl無法顯示在上面</pre><pre>view.addSubview(enterButton)</pre><pre>view.addSubview(passWrodLabel)</pre><pre>view.addSubview(passwordTextField)</pre><pre>view.addSubview(accountLabel)</pre><pre>view.addSubview(accountTextField)</pre><pre>setUpVedio()</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*yMZcExJpkx5AhYr9BDPnuw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*uKuq1C0j7MfYeJ_M1pucmQ.png" /></figure><h3>Breathe Page:</h3><p>功能：在滑動scorll View裡的button時，image和continue Button能同時變換顏色。</p><p>先拉Breathe相關Outlet:</p><pre><strong>//從最上面ImageView,再來contenLabel,最下面的UIButton</strong></pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> y1ImageView: UIImageView!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> contentLabel: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>var</strong> ContinueButton: UIView!</pre><pre>//scrollView裡的Buttons</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> anxietyButton: UIButton!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> angerButton: UIButton!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> fearButton: UIButton!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> sadnessButton: UIButton!</pre><p>用enum的方式，把所有scrollView的Button代表的顏色和Image跟ContinueButton的配色寫出來：</p><pre><strong>enum</strong> Buttons {</pre><pre><strong>case</strong> anxietyButton</pre><pre><strong>case</strong> angerButton</pre><pre><strong>case</strong> fearButton</pre><pre><strong>case</strong> sadnessButton</pre><pre>}<br></pre><pre><strong>func</strong> changeColor(on list :Buttons){</pre><pre><strong>switch</strong> list {</pre><pre><strong>case</strong>  .anxietyButton:</pre><pre>y1ImageView.backgroundColor = .purple</pre><pre>anxietyButton.backgroundColor = .purple</pre><pre>ContinueButton.backgroundColor = .purple<br></pre><pre><strong>case</strong> .angerButton:</pre><pre>y1ImageView.backgroundColor = .systemPink</pre><pre>angerButton.backgroundColor = .systemPink</pre><pre>ContinueButton.backgroundColor = .systemPink</pre><pre><strong>case</strong> .fearButton:</pre><pre>y1ImageView.backgroundColor = .green</pre><pre>fearButton.backgroundColor = .green</pre><pre>ContinueButton.backgroundColor = .green</pre><pre><strong>case</strong> .sadnessButton:</pre><pre>y1ImageView.backgroundColor = .blue</pre><pre>sadnessButton.backgroundColor = .blue</pre><pre>ContinueButton.backgroundColor = .blue<br><strong>break</strong></pre><pre>}</pre><pre>}</pre><p>點選第二個Button後，要讓其他的Button顏色都變成ClearColor必須在寫程式修改，不然按完所有ScrollView裡的Buttons顏色都會秀出來：</p><pre><strong>@IBAction</strong> <strong>func</strong> anxietyBtn(<strong>_</strong> sender: UIButton) {</pre><pre>changeColor(on: .anxietyButton)</pre><pre>anxietyButton.backgroundColor = .purple</pre><pre>angerButton.backgroundColor = .clear</pre><pre>fearButton.backgroundColor = .clear</pre><pre>sadnessButton.backgroundColor = .clear</pre><pre>}</pre><pre><strong>@IBAction</strong> <strong>func</strong> angerBtn(<strong>_</strong> sender: UIButton) {</pre><pre>changeColor(on: .angerButton)</pre><pre>anxietyButton.backgroundColor = .clear</pre><pre>angerButton.backgroundColor = .systemPink</pre><pre>fearButton.backgroundColor = .clear</pre><pre>sadnessButton.backgroundColor = .clear</pre><pre>}</pre><pre><strong>@IBAction</strong> <strong>func</strong> fearBtn(<strong>_</strong> sender: UIButton)</pre><pre>{</pre><pre>changeColor(on: .fearButton)</pre><pre>anxietyButton.backgroundColor = .clear</pre><pre>angerButton.backgroundColor = .clear</pre><pre>fearButton.backgroundColor = .green</pre><pre>sadnessButton.backgroundColor = .clear</pre><pre>}</pre><pre><strong>@IBAction</strong> <strong>func</strong> sadnessBtn(<strong>_</strong> sender: UIButton) {</pre><pre>changeColor(on: .sadnessButton)</pre><pre>anxietyButton.backgroundColor = .clear</pre><pre>angerButton.backgroundColor = .clear</pre><pre>fearButton.backgroundColor = .clear</pre><pre>sadnessButton.backgroundColor = .blue</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*z8kNbq8L1Y6Jbv6cU4Wq3g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*iA6PK07DQ4b72_Fz-cTJxA.png" /></figure><h3>Meditation Page:</h3><p>使用UISegmetnedControl做tableView畫面：</p><ol><li>SegmentedControl控制TabelViewController及ViewController加TableView：</li></ol><pre><strong>class</strong> meditationViewController: UIViewController {</pre><pre>//outlet代表segmentedControl的Course跟Single</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> firstView: UIView!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> secondView: UIView!</pre><pre><strong><br>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre>}<br> //以Ａlpha來寫SegContrl的效果，如果點選CourseSeg那ＳingleSeg的Ａlpha就會0消失，反之。</pre><pre><strong>@IBAction</strong> <strong>func</strong> segmented(<strong>_</strong> sender: UISegmentedControl) {</pre><pre><strong>if</strong> sender.selectedSegmentIndex == 0{</pre><pre>firstView.alpha = 1</pre><pre>secondView.alpha = 0</pre><pre>} <strong>else</strong>{</pre><pre>firstView.alpha = 0</pre><pre>secondView.alpha = 1</pre><pre>}</pre><pre>}</pre><pre>}</pre><p>2.練習用UITableViewController做出畫面。</p><p>3練習用ViewController和TableView做出畫面。</p><p>作品錄影：</p><p><a href="https://streamable.com/uoi3au">Simulator Screen Recording - iPhone 11 - 2021-09-21 at 01.20.46</a></p><p>GitHub:</p><p>目前檔案太大無法上傳成功，再研究研究。</p><p>Reference:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F8hs9coLSFOQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D8hs9coLSFOQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F8hs9coLSFOQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e44e1ffd1b8bb5df323bf625dca9ce7a/href">https://medium.com/media/e44e1ffd1b8bb5df323bf625dca9ce7a/href</a></iframe><p><a href="https://medium.com/@b36201/swift-%E8%A3%BD%E4%BD%9C%E7%A7%BB%E5%8B%95%E8%83%8C%E6%99%AF%E5%8B%95%E7%95%AB-af9632e96709">Swift-製作移動背景動畫</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FtcdEjazeYtY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DtcdEjazeYtY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FtcdEjazeYtY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/16b6fccb1e53c05a45adca5a985b7749/href">https://medium.com/media/16b6fccb1e53c05a45adca5a985b7749/href</a></iframe><p><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E5%88%A9%E7%94%A8-viewdidload-%E9%BB%9E%E4%B8%80%E9%A6%96%E6%AD%8C-%E6%92%AD%E6%94%BE%E4%B8%80%E6%AC%A1pl-bfe59e9e22c">利用 AVPlayer 播放音樂音效</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10cb1fab1b24" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E6%A8%A1%E4%BB%BFmeditationapp-10cb1fab1b24">模仿MeditationApp</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[autolayout in storyboard(Size-Class-Specific-Layout)]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/autolayout-in-storyboard-size-class-specific-layout-6ca6607f654a?source=rss-b8069b5e4cd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ca6607f654a</guid>
            <dc:creator><![CDATA[Pinyu]]></dc:creator>
            <pubDate>Sat, 31 Jul 2021 15:54:40 GMT</pubDate>
            <atom:updated>2021-08-01T15:29:39.305Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gjyGUmzT6moWhl3BJ7Q3KA.jpeg" /><figcaption>實作畫面</figcaption></figure><blockquote>遇到的問題：</blockquote><p>當畫面依照規則設計好時，為何在其他的設備上無法正確顯示(直向跟橫向）?</p><p>Ans:在那麼多的iphone和ipad上有不同大小的畫面，apple為這些不同尺寸大小環境(size Class)分成 ：</p><p>final Size:Compact-Compact, Compact-Regular, Regular-Compact, and Regular-Regular 。</p><p>compact是較受限制的空間的意思，Regular是不受限制的空間的意思，分別在垂直和水平方向時會有不同的類別。</p><p>但想知道自己所要設計的iphone尺寸是哪種？和哪些設備跟自己設計的是一樣的，也不用麻煩的去查，可以依照xcode裡的vary for traits(篩選器)的選項，來知道目前所選的畫面例如以iphone12Pro(可以選直向或橫向)畫面來設計畫面，在篩選器中點選與width和Height還篩選跟自己相同class環境。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W11L8n6pTEkq_mKy6qVXqQ.png" /></figure><blockquote>調整用於不同設備環境的例子：</blockquote><p>1:在storyboard選擇了一個iphone11的設備來設計，加入一個imageView做了top, leading,trailing簡單的設定</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJzOpzpndsdVA9qSABc-lA.png" /><figcaption>在preview裡把另外兩種不同類型的設備抓出來比較</figcaption></figure><p>2.此時在畫面是橫向時，imageView在SE的畫面完全不見了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6YNzSSLgxMQvIqviMJQXVg.png" /><figcaption>中間：iphone SE第二代</figcaption></figure><p>3:因為imageView在ＳＥ整個都往下跑了，所以先選一個top constraint條件，在install的位置加入ＳＥ橫向時的類別wC hC的類別</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*JZ0oHuouWE0_LMLffiB0_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z0pTQWa1mTvQp_O9n3WDMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*tKQpjGH3TiN9TPuMtnj2ZQ.png" /><figcaption>左一：選擇一個限制條件 中間：增加ＳＥ的類別 右邊：記得要把原本的installed選項取消</figcaption></figure><p>4.此時在outline的位置看見一個顏色較淺的條件設定，那就是這個代表SE畫面的top constaint,之後再根據imageView的位置做正確的constriant,就完成了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*Ql67nzMzvakm4L1-YvbHZA.png" /></figure><p>另外也可以使用installed來客制化畫面的Font,object backgroundColor…..</p><p>＊一樣在imageViewBackground的選項中選擇ＳＥ的屬性，再把顏色選成粉色：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zX9OrbRPqetd3XvFmq_SCQ.png" /><figcaption>左圖：SE的imageViewBackGround就變成粉色了</figcaption></figure><blockquote>另外在基本設定不清楚的地方筆記一下：</blockquote><p>*利用multiplier設定ImageView在view中的位置</p><ol><li>image.leading = safeArea.leading</li><li>image.top = safeArea.top</li><li>ImageView.centerX = 0.666 x centerX(imageView的寬度在view的2/3位置）</li><li>imageView.centerY = 0.5 x centerY(imageView的寬度在view的1/2位置）</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*ZgGiFtFmibRgia4oaKP8Xw.png" /></figure><blockquote>錯誤觀念：</blockquote><p>本以為需要設定物件的width,height,X,Y才是精確這個object的大小跟位置,但這樣過多的設定在物件複雜的畫面下會造成的條件衝突，其實只需要向以下的設定xcode就可以自動偵測物件的大小和更多彈性來調整物件位置。</p><p>設定所有width,height,X,Y的設定,都會影響物件的大小。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wLJaNtr9fnNcD9xqAy6H6g.png" /><figcaption>from: <a href="https://medium.com/p/6ca6607f654a/edit">https://medium.com/p/6ca6607f654a/edit</a></figcaption></figure><p>GitHub:</p><p><a href="https://github.com/annhuang777/autolayoutByStoryboard">GitHub - annhuang777/autolayoutByStoryboard</a></p><p>參考資料：</p><ul><li><a href="https://www.appcoda.com.tw/auto-layout/">Swift 新手系列之三：Auto Layout 介紹</a></li><li><a href="https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/Size-ClassSpecificLayout.html">Size-Class-Specific Layout</a></li><li><a href="https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/">Adaptivity and Layout - Visual Design - iOS - Human Interface Guidelines - Apple Developer</a></li><li><a href="https://franksios.medium.com/ios-%E6%9C%89%E9%97%9C%E6%96%BCautolayout%E4%B8%AD%E7%9A%84intrinsic-content-size-content-hugging-priority-content-compression-bd633d665fff">有關於Autolayout中的 Intrinsic Content Size、Content Hugging Priority、Content Compression Resistance…</a></li><li><a href="https://www.peko-step.com/zhtw/tool/tfcolor.html">色碼轉換器 （將 RGB 轉換成 HEX ／將 HEX 轉換成 RGB） | PEKO STEP</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ca6607f654a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/autolayout-in-storyboard-size-class-specific-layout-6ca6607f654a">autolayout in storyboard(Size-Class-Specific-Layout)</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#16 使用Storyboard建立LKMart購物app作業目標：以Storyboard建立購物流程（無程式）]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/16-%E4%BD%BF%E7%94%A8storyboard%E5%BB%BA%E7%AB%8Blkmart%E8%B3%BC%E7%89%A9app%E4%BD%9C%E6%A5%AD%E7%9B%AE%E6%A8%99-%E4%BB%A5storyboard%E5%BB%BA%E7%AB%8B%E8%B3%BC%E7%89%A9%E6%B5%81%E7%A8%8B-%E7%84%A1%E7%A8%8B%E5%BC%8F-f453269483af?source=rss-b8069b5e4cd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f453269483af</guid>
            <dc:creator><![CDATA[Pinyu]]></dc:creator>
            <pubDate>Fri, 17 Jul 2020 09:31:51 GMT</pubDate>
            <atom:updated>2022-05-07T12:17:39.922Z</atom:updated>
            <content:encoded><![CDATA[<h3>#16 使用Storyboard建立LKMart購物app</h3><p>作業目標：以Storyboard建立購物流程（無程式）</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*HRD9Y1r6fIUfmRx-ev3iIg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*j_tZLEw56xmDGXM562v_BA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*sYdBZoN7igwdV_PMoQWfzA.png" /><figcaption>左圖：利用button修圓角再載入新字體 。中間：簡單的lunchScreen。右圖：利用tabBarController搭配staticsCell做出有header的列表。</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*V6PHziDtBoKnpid5RXtwug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*GMFHRoRWoK62k3T9HUMOKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*eMR9OMDYQERoSly4zXiXQQ.png" /><figcaption>左一：利用scrollView做產品圖片的瀏覽 。中間：利用textView直接連結網頁。 右圖：使用searchBar</figcaption></figure><blockquote><strong>以下是完成的影片：</strong></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Fel5taa&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Fel5taa&amp;image=https%3A%2F%2Fcdn-cf-east.streamable.com%2Fimage%2Fel5taa.jpg%3FExpires%3D1595236140%26Signature%3DXfjjbOOe0bpddWz7AVK3ECTymAE2qEgYUeEeT8ZD4vuh%7EliZgSMIDC1rY5%7EhhlIwt7PWZjd07F-n8DzKJTQ4yA5FTM2Ly%7EDe3aIlZkQBE6GJZ-1lrvOIqkFr1mXF4G9Xa7kzu8nwrv%7E6tkvT-hAbPTxrQwZQtv1NzhtXmIcWQnWRDg7oOhFHN8cIfz33KAUK4aNXfyfKX4NEqxXw-MmzoTbWDbeIRNPoVP1Tt409qRNu9O-FRj9niG5m9wXVdl5wYL-JB5qiZuyny9wQSJKHrbNIwJyVlHXGhqyfaW4JqQ0ISTbBaHOkqcmpcMrqbjl7p3DX9BKqYUIOdefCpliKSg__%26Key-Pair-Id%3DAPKAIEYUVEN4EVB2OKEQ&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="352" height="720" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebce0f3b9d7b2920d2ad862e51d20232/href">https://medium.com/media/ebce0f3b9d7b2920d2ad862e51d20232/href</a></iframe><p>參考：</p><ul><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/storyboard-%E9%9B%BB%E5%AD%90%E6%9B%B8-app-%E6%90%AD%E9%85%8D-tab-controller-table-controller-navigation-controller-%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-ios-app-%E4%BD%9C%E6%A5%AD-aaa7e5f9165e">#24 Storyboard 電子書 App</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E7%82%BA-ios-app-%E5%8A%A0%E5%85%A5%E5%AE%A2%E8%A3%BD%E5%AD%97%E5%9E%8B-custom-font-d2b28b0269e0">為 iOS App 加入客製字型 (custom font)</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/%E4%B8%8D%E5%AF%AB%E4%B8%80%E8%A1%8C-swift-%E7%A8%8B%E5%BC%8F-%E9%BB%9E%E6%93%8A%E5%9C%96%E7%89%87%E9%A1%AF%E7%A4%BA%E7%B6%B2%E9%A0%81-75eb168610eb">不寫一行 Swift 程式，點擊圖片顯示網頁</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/%E7%B0%A1%E6%98%93%E8%AA%AA%E6%98%8Excode%E4%B8%ADobject-library%E7%9A%84text-view-493d65162648">『簡易說明Xcode』Object Library的Text View</a></li><li><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/stack-view-scroll-view-%E8%A3%BD%E4%BD%9C%E5%88%86%E9%A0%81-tutorial-%E6%87%B6%E5%BE%97%E5%AF%AB%E7%A8%8B%E5%BC%8F%E7%89%88-7ff9021317a0">stack view + scroll view 製作分頁 tutorial (懶得寫程式版)</a></li></ul><p>Ingredient:</p><ul><li><a href="https://www.lkmart.net/">LK MART - 精緻手感●質感生活 ｜家居物語</a></li><li><a href="https://unsplash.com/s/photos/food-and-drink">Food And Drink Pictures | Download Free Images &amp; Stock Photos on Unsplash</a></li></ul><p>GitHub:</p><p><a href="https://github.com/annhuang777/LKMart-storyboard-">annhuang777/LKMart-storyboard-</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f453269483af" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/16-%E4%BD%BF%E7%94%A8storyboard%E5%BB%BA%E7%AB%8Blkmart%E8%B3%BC%E7%89%A9app%E4%BD%9C%E6%A5%AD%E7%9B%AE%E6%A8%99-%E4%BB%A5storyboard%E5%BB%BA%E7%AB%8B%E8%B3%BC%E7%89%A9%E6%B5%81%E7%A8%8B-%E7%84%A1%E7%A8%8B%E5%BC%8F-f453269483af">#16 使用Storyboard建立LKMart購物app作業目標：以Storyboard建立購物流程（無程式）</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[＃14 以保養品來定義類別(屬性及方法）， 使用繼承，呼叫已存取的物件。]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/14-%E4%BB%A5%E4%BF%9D%E9%A4%8A%E5%93%81%E4%BE%86%E5%AE%9A%E7%BE%A9%E9%A1%9E%E5%88%A5-%E5%B1%AC%E6%80%A7%E5%8F%8A%E6%96%B9%E6%B3%95-%E4%BD%BF%E7%94%A8%E7%B9%BC%E6%89%BF-%E5%91%BC%E5%8F%AB%E5%B7%B2%E5%AD%98%E5%8F%96%E7%9A%84%E7%89%A9%E4%BB%B6-6f517b677c1e?source=rss-b8069b5e4cd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f517b677c1e</guid>
            <dc:creator><![CDATA[Pinyu]]></dc:creator>
            <pubDate>Tue, 07 Jul 2020 06:46:55 GMT</pubDate>
            <atom:updated>2020-07-07T07:03:57.745Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZkullQwLtRYAbJslSguEkQ.jpeg" /></figure><p>＊作業的目標：這次作業依照女生最清楚的臉部保養來做範例來理解，定義了三個類別（Class),使用了繼承（subclass:Superclass),及（override)覆寫superClass的function，也順便學學每天都用的保養品英文哈哈～</p><blockquote><strong>定義第一個基礎保養的class</strong></blockquote><pre><strong>class</strong> DialySkinCare{</pre><pre><strong>var</strong> toner:String = &quot;moistureToner&quot;</pre><pre><strong>var</strong> lotion:String = &quot;moistureLotion&quot;</pre><pre>}</pre><pre><strong>var</strong> todayDialyCare = DialySkinCare()</pre><pre>todayDialyCare.lotion</pre><pre>todayDialyCare.toner</pre><blockquote><strong>再延伸一個特別保養的Class作為基礎保養的繼承，包含屬性及方法</strong></blockquote><pre>//繼承基礎保養（DialySkinCare)在建立一個特別保養的類別（SpecilSkinCare)</pre><pre><strong>class</strong> SpecilSkinCare : DialySkinCare {</pre><pre><strong>var</strong> mask:String = &quot;highMoistureMask&quot;</pre><pre><strong>var</strong> eyeCream : String = &quot;IntensiveWrikling&quot;</pre><pre><strong>func</strong> allSkinCareStep() {</pre><pre>toner</pre><pre>lotion</pre><pre>mask</pre><pre>eyeCream   }</pre><pre>}</pre><pre><strong>var</strong> todaySpecilSkinCare = SpecilSkinCare()</pre><pre>todaySpecilSkinCare.mask</pre><pre>todaySpecilSkinCare.allSkinCareStep()</pre><p>＊這時候就可以在呼叫得時候發現已經繼承了之前基礎保養的選項：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KatyIYhnbs0e7wy3AVhxvQ.png" /></figure><blockquote><strong>又在定義第三個夏日保養繼承特別保養的類別，並使用到override覆寫保養步驟 allSkinCareStep()</strong></blockquote><pre><strong>class</strong> summerSkinCare:SpecilSkinCare{</pre><pre><strong>var</strong> Gel:String = &quot;AloeGel&quot;</pre><pre><strong>var</strong> WhiteningMask:String = &quot;IntensiveWhiteningMask&quot;</pre><pre>//使用override覆寫,因繼承夏日保養繼承基礎保養step多了gel及whtinengMask</pre><pre><strong>override</strong> <strong>func</strong> allSkinCareStep() {                           </pre><pre>}</pre><pre>}</pre><pre><strong>var</strong>  summerCare = summerSkinCare()</pre><pre>summerCare.Gel</pre><pre>summerCare.allSkinCareStep()</pre><p>＊結果所有步驟都顯示在allSkinCareStep()裡，<strong><em>但必須先用繼承之前的特別保養才能覆寫步驟</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_PcE15AHHlQWAGQPvZ3-Pw.png" /></figure><p>＿＿＿＿以上都是自己的理解可能還有很多不足，請多多指教＿＿＿＿＿</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f517b677c1e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/14-%E4%BB%A5%E4%BF%9D%E9%A4%8A%E5%93%81%E4%BE%86%E5%AE%9A%E7%BE%A9%E9%A1%9E%E5%88%A5-%E5%B1%AC%E6%80%A7%E5%8F%8A%E6%96%B9%E6%B3%95-%E4%BD%BF%E7%94%A8%E7%B9%BC%E6%89%BF-%E5%91%BC%E5%8F%AB%E5%B7%B2%E5%AD%98%E5%8F%96%E7%9A%84%E7%89%A9%E4%BB%B6-6f517b677c1e">＃14 以保養品來定義類別(屬性及方法）， 使用繼承，呼叫已存取的物件。</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[＃13 小費ＡＰＰ]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/13-%E5%B0%8F%E8%B2%BB%EF%BD%81%EF%BD%90%EF%BD%90-3733a36a4ffb?source=rss-b8069b5e4cd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3733a36a4ffb</guid>
            <dc:creator><![CDATA[Pinyu]]></dc:creator>
            <pubDate>Fri, 29 May 2020 07:39:30 GMT</pubDate>
            <atom:updated>2020-05-29T09:17:29.579Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AQO46dJB1mBdIP7g4QjmFQ.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstreamable.com%2Fo%2Fdzcjpo&amp;display_name=Streamable&amp;url=https%3A%2F%2Fstreamable.com%2Fdzcjpo&amp;image=https%3A%2F%2Fcdn-b-east.streamable.com%2Fimage%2Fdzcjpo.jpg%3Ftoken%3DSJmv0jKICvztEJoQz3MoHw%26expires%3D1590746160&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamable" width="724" height="1464" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f0042273cd4cda0a32383d2141500a5/href">https://medium.com/media/1f0042273cd4cda0a32383d2141500a5/href</a></iframe><pre><strong>import</strong> UIKit</pre><pre><strong>class</strong> ViewController: UIViewController {</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> priceTextField: UITextField!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> taxTextField: UITextField!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> personTextField: UITextField!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> totalLabel: UILabel!</pre><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> shareLabel: UILabel!</pre><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre>// Do any additional setup after loading the view.</pre><pre>}</pre><pre><strong>@IBAction</strong> <strong>func</strong> caculator(<strong>_</strong> sender: <strong>Any</strong>) {</pre><pre>//resignFirstResponder輸入完自動收起鍵盤</pre><pre>priceTextField.resignFirstResponder()</pre><pre>taxTextField.resignFirstResponder()</pre><pre>personTextField.resignFirstResponder()</pre><pre>//如果該輸入項目分為空白，則兩個計算項目會等於0</pre><pre><strong>if</strong> priceTextField.text == &quot;&quot;,taxTextField.text == &quot;&quot;,</pre><pre>personTextField.text == &quot;&quot; {</pre><pre>totalLabel.text == &quot;0&quot;</pre><pre>shareLabel.text == &quot;0&quot;</pre><pre>}<strong>else</strong>{</pre><pre>//Double()得的數為optional需要得出一個數值所以要！</pre><pre><strong>let</strong> tax = Double(priceTextField.text!)! * Double(taxTextField.text!)! / 100</pre><pre><strong>let</strong> total = Double(priceTextField.text!)! + tax</pre><pre><strong>let</strong> share = total / Double(personTextField.text!)!</pre><pre>totalLabel.text = String(total)</pre><pre>shareLabel.text = String(share)</pre><pre>}</pre><pre>}</pre><pre>//按下clear鍵清除後的狀態</pre><pre><strong>@IBAction</strong> <strong>func</strong> clear(<strong>_</strong> sender: <strong>Any</strong>) {</pre><pre>priceTextField.text = &quot;&quot;</pre><pre>taxTextField.text = &quot;&quot;</pre><pre>personTextField.text = &quot;&quot;</pre><pre>totalLabel.text = &quot;0&quot;</pre><pre>shareLabel.text = &quot;0&quot;</pre><pre>}</pre><pre>}</pre><p>參考:</p><p><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/%E5%B0%8F%E8%B2%BB-app-%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-ios-app-%E4%BD%9C%E6%A5%AD-89c3a831f82c">#35 換算 App，比方小費，BMI，BMR，匯率，單位換算</a></p><p>Github：</p><p><a href="https://github.com/annhuang777/payApp">annhuang777/payApp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3733a36a4ffb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/13-%E5%B0%8F%E8%B2%BB%EF%BD%81%EF%BD%90%EF%BD%90-3733a36a4ffb">＃13 小費ＡＰＰ</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#12 利用 viewDidLoad 客製 App 特效畫面]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/12-%E5%88%A9%E7%94%A8-viewdidload-%E5%AE%A2%E8%A3%BD-app-%E7%89%B9%E6%95%88%E7%95%AB%E9%9D%A2-29b7e638902e?source=rss-b8069b5e4cd2------2</link>
            <guid isPermaLink="false">https://medium.com/p/29b7e638902e</guid>
            <dc:creator><![CDATA[Pinyu]]></dc:creator>
            <pubDate>Tue, 05 May 2020 13:40:28 GMT</pubDate>
            <atom:updated>2020-05-14T05:57:50.595Z</atom:updated>
            <content:encoded><![CDATA[<h3>完成：<a href="https://streamable.com/2xe14y">https://streamable.com/2xe14y</a></h3><blockquote><strong>播放音樂＆重複播放&amp;音樂播放完畢提示＆設定指定播放區間</strong></blockquote><pre><strong>import</strong> UIKit</pre><pre>//音樂播放</pre><pre><strong>import</strong> AVFoundation</pre><pre><strong>class</strong> ViewController: UIViewController {</pre><pre>//音樂播放</pre><pre><strong>let</strong> player = AVPlayer()</pre><pre>//重複播放</pre><pre>//var loop = AVPlayerLooper?</pre><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre>// Do any additional setup after loading the view.</pre><pre>//使用Bundel.main.url叫出在demo檔案中的music url,forResource(檔名）withExtension(音樂格式）</pre><pre><strong>let</strong> fileUrl = Bundle.main.url(/service/forresource:&quot;summer&quot;,withExtension: &quot;mp3&quot;)!</pre><pre>//playitem:control timing and present situation</pre><pre><strong>let</strong> playItem = AVPlayerItem(url: fileUrl)</pre><pre>//replaceCurrenItem(with:):Replaces the current player item with a new player item.</pre><pre>player.replaceCurrentItem(with:playItem)</pre><pre>//*從何開始播放設定CMTime:A struct representing a time value such as a timestamp or duration</pre><pre>//50除2=在第25秒開始播放</pre><pre><strong>let</strong> time = CMTime(value: 50, timescale: 2)</pre><pre>//seek：區間</pre><pre>player.seek(to: time)</pre><pre>player.play()</pre><pre>//*播完提示</pre><pre>NotificationCenter.default.addObserver(forName: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: <strong>nil</strong>, queue: .main){</pre><pre>(<strong>_</strong>) <strong>in</strong></pre><pre>print(&quot;jump to next one&quot;)</pre><pre>}</pre><pre>//********重複播放</pre><pre>//使用檔案或網址</pre><pre>//if let //fileUrl = Bundle.main.url(/service/forresource:&quot;summer&quot;, withExtension: &quot;mp3&quot;) or</pre><pre>//musicUrl = URL(string: &quot;https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/AudioPreview118/v4/69/0e/98/690e98db-440d-cb0c-2bff-91b00a05bdda/mzaf_1674062311671795807.plus.aac.p.m4a&quot;)</pre><pre>//{</pre><pre>//AVQueuePlayer:順序播放</pre><pre>//let player = AVQueuePlayer()</pre><pre>//let item = AVPlayerItem(url: musicUrl)</pre><pre>//重複播放</pre><pre>//looper = AVPlayerLooper(player: player, templateItem: item)</pre><pre>player.play()</pre><p><strong>＊播完提示</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*p7sRNG-wbXqYbQKV4Z4__Q.png" /></figure><blockquote><strong>粒子效果</strong></blockquote><p>step1:建檔（file&gt;new&gt;file&gt;SpriteKitParticleFile)</p><p>step2:編輯粒子效果</p><p>step3:寫入程式：</p><pre>//********SpriteParticleKit粒子效果</pre><pre>//When a scene is presented by the view 所以要創造一個view</pre><pre><strong>let</strong> skView = SKView(frame: view.frame)</pre><pre>//利用insertSubView將skview當成背景(view = UIview,at:Subview indices start at 0 and cannot be greater than the number of subviews)</pre><pre>view.insertSubview(skView, at: 0)</pre><pre>//skSene:An object that organizes all of the active SpriteKit content.</pre><pre><strong>let</strong> scene = SKScene(size: skView.frame.size)</pre><pre>//利用skview呼叫scene</pre><pre>skView.presentScene(scene)</pre><pre>//scene的位置</pre><pre>scene.anchorPoint = CGPoint(x: 0.8, y: 0.8)</pre><pre>//SKEmitterNode呈現粒子效果的程式</pre><pre><strong>let</strong> emitterNode = SKEmitterNode(fileNamed: &quot;MyBubbleParticle&quot;)</pre><pre>//利用addChild讓粒子效果加入scene</pre><pre>scene.addChild(emitterNode!)</pre><p><a href="https://developer.apple.com/documentation/spritekit/skscene/creating_a_scene_from_a_file">Creating a Scene from a File</a></p><blockquote>GIF實現多張圖片連續播放的動畫</blockquote><pre>//GIF動畫</pre><pre>//設定動畫的位置跟大小</pre><pre><strong>let</strong> imageView = UIImageView(frame: CGRect(x: 350, y:350 , width: 500, height: 50))</pre><pre>//動畫用addSubView當背景</pre><pre>view.addSubview(imageView)</pre><pre>//duration:The duration of the animation.數值越小效果越快</pre><pre><strong>let</strong> animatedImage = UIImage.animatedImageNamed(&quot;0509ffebe6f44630dbff896708cef7122Cjz4m8nVpn9y3HT-&quot;, duration: 0)</pre><pre>imageView.image = animatedImage                                         </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*N2cBzNx0ufw8atyWgkf_sA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*JqMqdMX_EX_ZCu5wlEqKPQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*ekfEBjvUHjly3rqwpPKIJw.png" /></figure><blockquote>漸層效果</blockquote><pre><strong>import</strong> UIKit</pre><pre><strong>class</strong> ViewController: UIViewController {</pre><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {</pre><pre><strong>super</strong>.viewDidLoad()</pre><pre><strong>let</strong> gradientLayer = CAGradientLayer()</pre><pre>gradientLayer.frame = view.bounds</pre><pre>gradientLayer.colors =</pre><pre>[UIColor.yellow.cgColor,</pre><pre>UIColor.gray.cgColor,</pre><pre>UIColor.orange.cgColor]</pre><pre>//漸層由左到右</pre><pre>gradientLayer.startPoint = CGPoint(x: 0, y: 0.5)</pre><pre>gradientLayer.endPoint = CGPoint(x: 1, y: 0.5)</pre><pre>//按照自己想要的顏色分配比例(介於0-1)</pre><pre>gradientLayer.locations = [0,0.8,1]</pre><pre>//使用insertSublayer不會把蛋糕圖案遮住</pre><pre>view.layer.insertSublayer(gradientLayer, at: 0)</pre><pre>// Do any additional setup after loading the view.</pre><pre>}}</pre><p>參考：</p><p><a href="https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84%E8%A9%A6%E7%85%89-%E5%8B%87%E8%80%85%E7%9A%84-100-%E9%81%93-swift-ios-app-%E8%AC%8E%E9%A1%8C/%E5%88%A9%E7%94%A8-controller-%E7%9A%84-viewdidload-%E8%A3%BD%E4%BD%9C%E5%90%B8%E7%9D%9B-app-%E7%95%AB%E9%9D%A2-8e4d02d86177">#91 自訂 controller 類別和利用 viewDidLoad 客製 App 畫面</a></p><p>Github:</p><p><a href="https://github.com/annhuang777/AVFountion-SpriteParticle">annhuang777/AVFountion-SpriteParticle</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29b7e638902e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/12-%E5%88%A9%E7%94%A8-viewdidload-%E5%AE%A2%E8%A3%BD-app-%E7%89%B9%E6%95%88%E7%95%AB%E9%9D%A2-29b7e638902e">#12 利用 viewDidLoad 客製 App 特效畫面</a> was originally published in <a href="https://medium.com/peter-pan-swift-ios-class">彼得潘的 Swift iOS / Flutter App 開發教室</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>