<?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 Adam on Medium]]></title>
        <description><![CDATA[Stories by Adam on Medium]]></description>
        <link>https://medium.com/@bgisgone?source=rss-d1d3fbf1cc26------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FmhUp_pV8Z-sEYytR4eP5w.jpeg</url>
            <title>Stories by Adam on Medium</title>
            <link>https://medium.com/@bgisgone?source=rss-d1d3fbf1cc26------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 02:43:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bgisgone/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[#30 使用 List 和 ForEach 顯示多筆資料搭配自訂的資料型別和 row_蜘蛛人電影]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/30-%E4%BD%BF%E7%94%A8list%E5%92%8Cforeach%E9%A1%AF%E7%A4%BA%E5%A4%9A%E7%AD%86%E8%B3%87%E6%96%99%E6%90%AD%E9%85%8D%E8%87%AA%E8%A8%82%E7%9A%84%E8%B3%87%E6%96%99%E5%9E%8B%E5%88%A5%E5%92%8Crow-%E8%9C%98%E8%9B%9B%E4%BA%BA%E9%9B%BB%E5%BD%B1-9b3fb1ed20de?source=rss-d1d3fbf1cc26------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b3fb1ed20de</guid>
            <dc:creator><![CDATA[Adam]]></dc:creator>
            <pubDate>Sun, 23 Aug 2026 10:52:38 GMT</pubDate>
            <atom:updated>2026-08-23T14:33:54.162Z</atom:updated>
            <content:encoded><![CDATA[<p>SwiftUI作業4練習</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*vxADxj6RRnSwIsBqrfAvkQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rxZdOj7M3XnmsCT-WoTcWw.png" /></figure><p>按照彼得範例的四個步驟</p><ol><li>建立 Model</li><li>建立 SampleData</li><li>建立 Row View</li><li>建立 List</li></ol><p>自訂資料型別 Model</p><pre>import Foundation<br><br>struct Movie: Identifiable {<br>    let id = UUID()      // 唯一識別碼，讓 SwiftUI 的 List 可以辨識每一筆資料<br>    let title: String    // 電影名稱<br>    let year: Int        // 電影上映年份<br>    let actor: String    // 飾演蜘蛛人的演員<br>    let rating: Double    // IMDb 評分<br>    let imageName: String  // 圖片名稱<br>}</pre><p>請AI幫忙生成蜘蛛人系列電影的SampleData</p><pre>import Foundation<br><br>struct SampleData {<br>    static let movies = [<br>        <br>        // MARK: - Tom Holland<br>        <br>        Movie(<br>            title: &quot;Spider-Man: Brand New Day&quot;,<br>            year: 2026,<br>            actor: &quot;Tom Holland&quot;,<br>            rating: 8.2,<br>            imageName: &quot;spiderman_brand_new_day&quot;<br>        ),<br>        <br>        Movie(<br>            title: &quot;Spider-Man: No Way Home&quot;,<br>            year: 2021,<br>            actor: &quot;Tom Holland&quot;,<br>            rating: 8.1,<br>            imageName: &quot;spiderman_no_way_home&quot;<br>        ),<br>        <br>        Movie(<br>            title: &quot;Spider-Man: Far From Home&quot;,<br>            year: 2019,<br>            actor: &quot;Tom Holland&quot;,<br>            rating: 7.3,<br>            imageName: &quot;spiderman_far_from_home&quot;<br>        ),<br>        <br>        Movie(<br>            title: &quot;Spider-Man: Homecoming&quot;,<br>            year: 2017,<br>            actor: &quot;Tom Holland&quot;,<br>            rating: 7.4,<br>            imageName: &quot;spiderman_homecoming&quot;<br>        ),<br>        <br>        // MARK: - Andrew Garfield<br>        <br>        Movie(<br>            title: &quot;The Amazing Spider-Man 2&quot;,<br>            year: 2014,<br>            actor: &quot;Andrew Garfield&quot;,<br>            rating: 6.6,<br>            imageName: &quot;amazing_spiderman_2&quot;<br>        ),<br>        <br>        Movie(<br>            title: &quot;The Amazing Spider-Man&quot;,<br>            year: 2012,<br>            actor: &quot;Andrew Garfield&quot;,<br>            rating: 7.0,<br>            imageName: &quot;amazing_spiderman&quot;<br>        ),<br>        <br>        // MARK: - Tobey Maguire<br>        <br>        Movie(<br>            title: &quot;Spider-Man 3&quot;,<br>            year: 2007,<br>            actor: &quot;Tobey Maguire&quot;,<br>            rating: 6.3,<br>            imageName: &quot;spiderman_3&quot;<br>        ),<br>        <br>        Movie(<br>            title: &quot;Spider-Man 2&quot;,<br>            year: 2004,<br>            actor: &quot;Tobey Maguire&quot;,<br>            rating: 7.5,<br>            imageName: &quot;spiderman_2&quot;<br>        ),<br>        <br>        Movie(<br>            title: &quot;Spider-Man&quot;,<br>            year: 2002,<br>            actor: &quot;Tobey Maguire&quot;,<br>            rating: 7.4,<br>            imageName: &quot;spiderman_2002&quot;<br>        )<br>    ]<br>}</pre><p>建立 Row View</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DhHhJTDEFzXePM6UD7NJAg.png" /></figure><p>建立 List ，完成!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBfSTWkX9tHXyzmXi8hM0A.png" /></figure><blockquote><strong>Github:</strong></blockquote><p><a href="https://github.com/ggisfun/MovieList_SpiderMan.git">GitHub - ggisfun/MovieList_SpiderMan: Swift List 練習，蜘蛛人電影</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b3fb1ed20de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/30-%E4%BD%BF%E7%94%A8list%E5%92%8Cforeach%E9%A1%AF%E7%A4%BA%E5%A4%9A%E7%AD%86%E8%B3%87%E6%96%99%E6%90%AD%E9%85%8D%E8%87%AA%E8%A8%82%E7%9A%84%E8%B3%87%E6%96%99%E5%9E%8B%E5%88%A5%E5%92%8Crow-%E8%9C%98%E8%9B%9B%E4%BA%BA%E9%9B%BB%E5%BD%B1-9b3fb1ed20de">#30 使用 List 和 ForEach 顯示多筆資料搭配自訂的資料型別和 row_蜘蛛人電影</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[#29 模仿 App Store 上架 App，製作一頁精美的 App 畫面-台灣彩券]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/29-%E6%A8%A1%E4%BB%BF-app-store-%E4%B8%8A%E6%9E%B6-app-%E8%A3%BD%E4%BD%9C%E4%B8%80%E9%A0%81%E7%B2%BE%E7%BE%8E%E7%9A%84-app-%E7%95%AB%E9%9D%A2-%E5%8F%B0%E7%81%A3%E5%BD%A9%E5%88%B8-9c2056189110?source=rss-d1d3fbf1cc26------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c2056189110</guid>
            <dc:creator><![CDATA[Adam]]></dc:creator>
            <pubDate>Sun, 16 Aug 2026 10:27:19 GMT</pubDate>
            <atom:updated>2026-08-16T14:58:18.794Z</atom:updated>
            <content:encoded><![CDATA[<p>SwiftUI作業練習之好想中頭獎～</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*dLsU1ByzmCPoVF2q0kJM4w.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i795GW-oHQ8sLhF4av6DBg.png" /><figcaption>(左) : 原圖 ; (右) 練習作業</figcaption></figure><p>分成三層<br>(1)背景BackgroundView<br>(2)顯示彩券的RowView，搭配ScrollView<br>(3)底部的TabBarView</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cukVB4W6RTvb4XYe846WCg.png" /></figure><blockquote><strong>1.背景BackgroundView</strong></blockquote><p>背景上方的綠色區塊<strong>HeaderShape，</strong>先用自訂曲線的方式模仿畫出弧度</p><pre>struct HeaderShape: Shape {<br>    func path(in rect: CGRect) -&gt; Path {<br>        var path = Path()<br><br>        let bottomY = rect.height<br>        let curveStartY: CGFloat = 201<br>        let curveWidth: CGFloat = 55<br><br>        path.move(to: CGPoint(x: 0, y: 0))<br><br>        path.addLine(to: CGPoint(x: rect.width, y: 0))<br><br>        path.addLine(<br>            to: CGPoint(<br>                x: rect.width,<br>                y: curveStartY<br>            )<br>        )<br><br>        // 右下曲線<br>        path.addCurve(<br>            to: CGPoint(<br>                x: rect.width - curveWidth,<br>                y: bottomY<br>            ),<br>            control1: CGPoint(<br>                x: rect.width - 8,<br>                y: 215<br>            ),<br>            control2: CGPoint(<br>                x: rect.width - 25,<br>                y: 221<br>            )<br>        )<br><br>        // 底部<br>        path.addLine(<br>            to: CGPoint(<br>                x: curveWidth,<br>                y: bottomY<br>            )<br>        )<br><br>        // 左下曲線<br>        path.addCurve(<br>            to: CGPoint(<br>                x: 0,<br>                y: curveStartY<br>            ),<br>            control1: CGPoint(<br>                x: 25,<br>                y: 221<br>            ),<br>            control2: CGPoint(<br>                x: 8,<br>                y: 215<br>            )<br>        )<br><br>        path.closeSubpath()<br><br>        return path<br>    }<br>}</pre><p>把<strong>HeaderShape</strong>用ZStack 疊上去並加上<strong>ignoresSafeArea(edges: .top)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A57UYq8FVR4VDl1nLvbxeA.png" /></figure><blockquote><strong>2.顯示彩券資料的RowView</strong></blockquote><p><strong>BingoLotteryInfoView =&gt; </strong>顯示賓果賓果<strong><br>LotteryInfoView =&gt; </strong>其他彩券類型共用<br>因為大部分的彩券資料格式都很類似，除了賓果賓果的資料比較多以外，其他類型都可以共用。</p><p><strong>LotteryInfoView</strong></p><pre>import SwiftUI<br><br>struct LotteryInfoView: View {<br>    let lottery: LotteryInfo<br>    <br>    var body: some View {<br>        <br>        VStack {<br>            HStack(alignment: .center) {<br>                Image(lottery.imageName)<br>                    .resizable()<br>                    .scaledToFit()<br>                    .frame(width: 130, height: 56)<br>                <br>                Spacer()<br>                <br>                VStack(alignment: .trailing) {<br>                    HStack(spacing: 0) {<br>                        Text(&quot;下次開獎日&quot;)<br>                            .font(.system(size: 13))<br>                        <br>                        Spacer()<br>                            .frame(width: 12)<br>                        <br>                        Image(systemName: &quot;calendar&quot;)<br>                            .font(.system(size: 15, weight: .bold))<br>                            .frame(width: 28, height: 14)<br>                            .foregroundStyle(<br>                                LinearGradient(<br>                                    colors: [<br>                                        Color(<br>                                            red: 241.0 / 255.0,<br>                                            green: 160.0 / 255.0,<br>                                            blue: 78.0 / 255.0<br>                                        ),<br>                                        Color(<br>                                            red: 237.0 / 255.0,<br>                                            green: 107.0 / 255.0,<br>                                            blue: 0<br>                                        )<br>                                    ],<br>                                    startPoint: .top,<br>                                    endPoint: .bottom<br>                                )<br>                            )<br>                        <br>                        Text(lottery.drawDate)<br>                            .font(.system(size: 15, weight: .medium))<br>                            .foregroundStyle(<br>                                Color(<br>                                    red: 207.0 / 255.0,<br>                                    green: 23.0 / 255.0,<br>                                    blue: 0<br>                                )<br>                            )<br>                    }<br>                    <br>                    Text(lottery.jackpotTitle)<br>                        .font(.system(size: 13))<br>                        .foregroundStyle(<br>                            lottery.jackpotTitle.isEmpty<br>                            ? Color.clear<br>                            : Color.primary<br>                        )<br>                        .frame(height: 16)<br>                    <br>                    Text(lottery.jackpotAmount)<br>                        .font(.system(size: 26.5, weight: .bold))<br>                        .foregroundStyle(<br>                            lottery.jackpotAmount.isEmpty<br>                            ? Color.clear<br>                            : Color(<br>                                red: 234.0 / 255.0,<br>                                green: 51.0 / 255.0,<br>                                blue: 36.0 / 255.0<br>                            )<br>                        )<br>                        .frame(height: 32)<br>                }<br>            }<br>            <br>            HStack {<br>                Text(lottery.period)<br>                    .font(.system(size: 15, weight: .medium))<br>                Spacer()<br>                Text(lottery.secondTitle)<br>                    .font(.system(size: 15))<br>                    .foregroundStyle(<br>                        lottery.secondTitle.isEmpty<br>                        ? Color.clear<br>                        : Color(<br>                            red: 199.0 / 255.0,<br>                            green: 0,<br>                            blue: 0<br>                        )<br>                    )<br>            }<br>            <br>            if !lottery.isDrawNumbersHidden {<br>                GeometryReader { proxy in<br>                    let spacing: CGFloat = 6<br>                    let ballSize = (proxy.size.width - spacing * 6) / 7<br><br>                    HStack(spacing: spacing) {<br>                        ForEach(0..&lt;7) { index in<br>                            if index &lt; lottery.firstNumbers.count {<br>                                ZStack {<br>                                    Circle()<br>                                        .fill(lottery.firstBallColor)<br><br>                                    Text(lottery.firstNumbers[index])<br>                                        .font(.system(size: 18, weight: .bold))<br>                                        .foregroundStyle(.black)<br>                                }<br>                                .frame(width: ballSize, height: ballSize)<br>                            } else if index == 6 {<br>                                ZStack {<br>                                    Circle()<br>                                        .fill(lottery.secondBallColor)<br><br>                                    Text(lottery.secondNumber)<br>                                        .font(.system(size: 18, weight: .bold))<br>                                        .foregroundStyle(.white)<br>                                }<br>                                .frame(width: ballSize, height: ballSize)<br>                            } else {<br>                                Color.clear<br>                                    .frame(width: ballSize, height: ballSize)<br>                            }<br>                        }<br>                    }<br>                    .frame(maxWidth: .infinity)<br>                }<br>                .frame(height: 48)<br>            }<br>            <br>            <br>        }<br>        .padding(6)<br>        .background(Color.white)<br>        .cornerRadius(10)<br>                <br>    }<br>}</pre><p><strong>BingoLotteryInfoView</strong></p><pre>import SwiftUI<br><br>struct BingoLotteryInfoView: View {<br>    let lottery: LotteryInfo<br><br>    private let columns = Array(<br>        repeating: GridItem(.flexible(minimum: 0), spacing: 6),<br>        count: 7<br>    )<br><br>    var body: some View {<br>        VStack(alignment: .leading, spacing: 20) {<br>            header<br><br>            Text(lottery.period)<br>                .font(.system(size: 14, weight: .medium))<br><br>            LazyVGrid(columns: columns, spacing: 10) {<br>                ForEach(lottery.firstNumbers, id: \.self) { number in<br>                    BingoBall(<br>                        number: number,<br>                        color: lottery.highlightedNumbers.contains(number)<br>                            ? Color(<br>                                red: 206.0 / 255.0,<br>                                green: 55.0 / 255.0,<br>                                blue: 46.0 / 255.0<br>                            )<br>                            : lottery.firstBallColor,<br>                        textColor: lottery.highlightedNumbers.contains(number)<br>                            ? .white<br>                            : .black<br>                    )<br>                    .frame(maxWidth: .infinity)<br>                }<br>            }<br><br>            LazyVGrid(columns: columns, alignment: .leading, spacing: 10) {<br>                ForEach(lottery.bingoResults) { result in<br>                    VStack(spacing: 8) {<br>                        Text(result.title)<br>                            .font(.system(size: 13, weight: .regular))<br>                            .foregroundStyle(result.ballColor)<br>                            .lineLimit(1)<br>                            .minimumScaleFactor(0.7)<br><br>                        BingoBall(<br>                            number: result.value,<br>                            color: result.ballColor,<br>                            textColor: .white<br>                        )<br>                        .frame(maxWidth: .infinity)<br>                    }<br>                }<br>            }<br>        }<br>        .padding(6)<br>        .background(.white, in: RoundedRectangle(cornerRadius: 10))<br>    }<br><br>    private var header: some View {<br>        HStack(alignment: .top) {<br>            Image(lottery.imageName)<br>                .resizable()<br>                .scaledToFit()<br>                .frame(width: 130, height: 56)<br><br>            Spacer()<br><br>            HStack(spacing: 0) {<br>                Text(&quot;下次開獎日&quot;)<br>                    .font(.system(size: 13))<br><br>                Spacer()<br>                    .frame(width: 12)<br><br>                Image(systemName: &quot;calendar&quot;)<br>                    .font(.system(size: 15, weight: .bold))<br>                    .frame(width: 28, height: 14)<br>                    .foregroundStyle(<br>                        LinearGradient(<br>                            colors: [<br>                                Color(<br>                                    red: 241.0 / 255.0,<br>                                    green: 160.0 / 255.0,<br>                                    blue: 78.0 / 255.0<br>                                ),<br>                                Color(<br>                                    red: 237.0 / 255.0,<br>                                    green: 107.0 / 255.0,<br>                                    blue: 0<br>                                )<br>                            ],<br>                            startPoint: .top,<br>                            endPoint: .bottom<br>                        )<br>                    )<br><br>                Text(lottery.drawDate)<br>                    .font(.system(size: 15, weight: .medium))<br>                    .foregroundStyle(<br>                        Color(<br>                            red: 207.0 / 255.0,<br>                            green: 23.0 / 255.0,<br>                            blue: 0<br>                        )<br>                    )<br>            }<br>            .fixedSize()<br>        }<br>        .padding(6)<br>    }<br>}<br><br>private struct BingoBall: View {<br>    let number: String<br>    let color: Color<br>    let textColor: Color<br><br>    var body: some View {<br>        Circle()<br>            .fill(color)<br>            .aspectRatio(1, contentMode: .fit)<br>            .overlay {<br>                Text(number)<br>                    .font(.system(size: 18, weight: .bold))<br>                    .foregroundStyle(textColor)<br>            }<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MJREdYcpC2hqhq2BdpCBGg.png" /></figure><blockquote><strong>3.底部TabBarView</strong></blockquote><p>中間圓形顯示對獎小幫手的部分自己一層，在用ZStack加上去</p><pre>import SwiftUI<br><br>struct TabBarView: View {<br>    var body: some View {<br>        ZStack {<br>            HStack {<br>                HStack(spacing: 36) {<br>                    VStack {<br>                        Image(systemName: &quot;house.fill&quot;)<br>                            .resizable()<br>                            .scaledToFit()<br>                            .frame(width: 28, height: 28)<br>                            .foregroundStyle(.gray)<br>                        Text(&quot;首頁&quot;)<br>                            .font(Font.system(size: 11))<br>                            .foregroundStyle(.gray)<br>                    }<br>                    VStack {<br>                        Image(systemName: &quot;8.circle.fill&quot;)<br>                            .resizable()<br>                            .scaledToFit()<br>                            .frame(width: 28, height: 28)<br>                        Text(&quot;獎號資訊&quot;)<br>                            .font(Font.system(size: 11))<br>                    }<br>                    .foregroundStyle(<br>                        Color(<br>                            red: 52.0 / 255.0,<br>                            green: 119.0 / 255.0,<br>                            blue: 120.0 / 255.0<br>                        )<br>                    )<br>                    <br>                }<br>                Spacer()<br>                HStack(spacing: 38) {<br>                    VStack {<br>                        Image(systemName: &quot;list.bullet.clipboard.fill&quot;)<br>                            .resizable()<br>                            .scaledToFit()<br>                            .frame(width: 28, height: 28)<br>                            .foregroundStyle(Color.gray)<br>                        Text(&quot;選號紀錄&quot;)<br>                            .font(Font.system(size: 11))<br>                            .foregroundStyle(.gray)<br>                    }<br>                    VStack {<br>                        Image(systemName: &quot;ellipsis.circle.fill&quot;)<br>                            .resizable()<br>                            .scaledToFit()<br>                            .frame(width: 28, height: 28)<br>                            .foregroundStyle(.gray)<br>                        Text(&quot;更多&quot;)<br>                            .font(Font.system(size: 11))<br>                            .foregroundStyle(.gray)<br>                    }<br>                    <br>                }<br>            }<br>            .padding(.horizontal, 24)<br>            .offset(y: -12)<br>            .frame(height: 86)<br>            <br>            ZStack {<br>                Circle()<br>                    .fill(<br>                        LinearGradient(<br>                            colors: [<br>                                Color(<br>                                    red: 96.0 / 255.0,<br>                                    green: 202.0 / 255.0,<br>                                    blue: 188.0 / 255.0<br>                                ),<br>                                Color(<br>                                    red: 42.0 / 255.0,<br>                                    green: 100.0 / 255.0,<br>                                    blue: 93.0 / 255.0<br>                                )<br>                            ],<br>                            startPoint: .top,<br>                            endPoint: .bottom<br>                        )<br>                    )<br>                    .frame(width: 72, height: 72)<br><br>                VStack(spacing:10) {<br>                    Image(systemName: &quot;qrcode&quot;)<br>                        .resizable()<br>                        .scaledToFit()<br>                        .frame(width: 28, height: 28)<br>                    Text(&quot;對獎小幫手&quot;)<br>                        .font(Font.system(size: 11))<br>                }<br>                .foregroundStyle(.white)<br>            }.offset(y: -30)<br>            <br>            <br>        }<br>        .background {<br>            RoundedRectangle(cornerRadius: 10)<br>                .fill(Color.white)<br>                .shadow(<br>                    color: Color.black.opacity(0.15),<br>                    radius: 8,<br>                    x: 0,<br>                    y: -2<br>                )<br>        }<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*-1_1w68oZJBdDqtBC9VCuA.png" /></figure><blockquote><strong>4.整合顯示</strong></blockquote><p>最後回到<strong>ContentView </strong>把所有畫面整合顯示</p><pre>import SwiftUI<br><br>struct ContentView: View {<br>    var body: some View {<br>        <br>        ZStack {<br>            BackgroundView()<br>            VStack(spacing: 22) {<br>                Text(&quot;獎號資訊&quot;)<br>                    .font(.system(size: 20, weight: .bold))<br>                    .foregroundStyle(.white)<br><br>                ScrollView {<br>                    LazyVStack(alignment: .leading,spacing: 10) {<br>                        ForEach(LotteryInfo.sampleData) { lottery in<br>                            if lottery.displayStyle == .bingo {<br>                                BingoLotteryInfoView(lottery: lottery)<br>                            } else {<br>                                LotteryInfoView(lottery: lottery)<br>                            }<br>                        }<br>                        Text(&quot;中獎號碼以獨立公正人士簽署之紀錄表為準&quot;)<br>                            .font(Font.system(size: 15))<br>                            .foregroundStyle(<br>                                Color(<br>                                    red: 54.0 / 255.0,<br>                                    green: 54.0 / 255.0,<br>                                    blue: 63.0 / 255.0<br>                                )<br>                            )<br>                            .frame(height: 30)<br>                    }<br>                }<br>                .padding(.horizontal ,10)<br>                <br>            }<br>            <br>            <br>            VStack {<br>                Spacer()<br>                TabBarView()<br>            }<br>            .ignoresSafeArea(edges: .all)<br>            <br>        }<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*9mfsZdNPtzd-XGAjigROoA.png" /></figure><blockquote><strong>Github<em>:</em></strong></blockquote><p><a href="https://github.com/ggisfun/OnePage_LotteryTW.git">GitHub - ggisfun/OnePage_LotteryTW: SwiftUI OnePage 台灣彩券</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c2056189110" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/29-%E6%A8%A1%E4%BB%BF-app-store-%E4%B8%8A%E6%9E%B6-app-%E8%A3%BD%E4%BD%9C%E4%B8%80%E9%A0%81%E7%B2%BE%E7%BE%8E%E7%9A%84-app-%E7%95%AB%E9%9D%A2-%E5%8F%B0%E7%81%A3%E5%BD%A9%E5%88%B8-9c2056189110">#29 模仿 App Store 上架 App，製作一頁精美的 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>
        <item>
            <title><![CDATA[#28 UICollectionViewCompositionalLayout練習_Disney+]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/28-uicollectionviewcompositionallayout%E7%B7%B4%E7%BF%92-disney-56dc7ab6ab2c?source=rss-d1d3fbf1cc26------2</link>
            <guid isPermaLink="false">https://medium.com/p/56dc7ab6ab2c</guid>
            <dc:creator><![CDATA[Adam]]></dc:creator>
            <pubDate>Wed, 26 Mar 2025 15:42:41 GMT</pubDate>
            <atom:updated>2025-03-26T16:06:14.820Z</atom:updated>
            <content:encoded><![CDATA[<p>練習使用UICollectionViewCompositionalLayout模仿製作Disney+ APP 的頁面排版。</p><blockquote><strong>DEMO:</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XNl9eHImH-fmQwS7DoFt1w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PvgVC0UWWOQCpfmdcSAqvA.png" /><figcaption>(左) : APP原圖 ; (右) DEMO</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*xlTVcRX_sG8SdVLP1hIGRw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*cc7faITJWFiiTgXeydUBsg.gif" /><figcaption>(左) : APP原圖 ; (右) DEMO</figcaption></figure><p>先用enum建立要顯示的5個section 資料，第一個section 只是要用header來顯示Logo，不顯示item所以數量設定成0。</p><pre>import UIKit<br><br>enum Section: String, CaseIterable {<br>    case logo = &quot;logo&quot;<br>    case popular = &quot;popular&quot;<br>    case theme = &quot;theme&quot;<br>    case newRelease = &quot;Disney+ 最新上架&quot;<br>    case recommend = &quot;推薦給您&quot;<br>    <br>    var itemCount: Int {<br>        switch self {<br>        case .logo:<br>            return 0<br>        case .hot:<br>            return 10<br>        case .theme:<br>            return 6<br>        case .newRelease:<br>            return 10<br>        case .recommend:<br>            return 10<br>        }<br>    }<br>}<br><br>let sectionData: [Section] = Section.allCases</pre><p>Compositional Layout 主要由Item、Group、Section組成，一層包一層。先設定 Item 放進 Group 裡，在設定 Group 放進 Section，最後在返回Section。</p><p>設定寬/高可以用4種方法設定</p><ul><li>fractionalWidth(CGFloat) =&gt; 相對於父容器的寬度</li><li>fractionalHeight(CGFloat) =&gt; 相對於父容器的高度</li><li>absolute(CGFloat) =&gt; 固定尺寸</li><li>estimated(CGFloat) =&gt; 預估尺寸</li></ul><p>Group 還可以設定排列方式是 水平 (horizontal)或垂直 (vertical)</p><blockquote><strong>1.設定第一個顯示 Logo 的 section</strong></blockquote><p>建立一個headerView， 類別是UICollectionReusableView，用來放 Logo 圖片的空間，然後用section.boundarySupplementaryItems 加入header，如果是要加footer， 把 alignment 改成 .bottom 就會變成出現在 cell 下方。</p><pre>   // 放圖片的header view<br>   class LogoHeaderView: UICollectionReusableView {<br>        static let identifier = &quot;LogoHeaderView&quot;<br>        override init(frame: CGRect) {<br>            super.init(frame: frame)<br>        }<br>            <br>        required init?(coder: NSCoder) {<br>            super.init(coder: coder)<br>        }<br>    }    <br><br><br>    // 設定section<br>    private func createLogoSection() -&gt; NSCollectionLayoutSection {<br>        // 佔滿螢幕寬度，高度110 =&gt; 圖片高度50 + 起始位置60<br>        let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(110))<br>        let header = NSCollectionLayoutBoundarySupplementaryItem(<br>            layoutSize: headerSize,<br>            elementKind: UICollectionView.elementKindSectionHeader,<br>            alignment: .top<br>        )<br>        <br>        let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(1))<br>        let item = NSCollectionLayoutItem(layoutSize: itemSize)<br>        let group = NSCollectionLayoutGroup.vertical(layoutSize: itemSize, subitems: [item])<br>        let section = NSCollectionLayoutSection(group: group)<br>        section.boundarySupplementaryItems = [header]<br>        <br>        return section<br>    }<br><br>    // Logo 圖片設定<br>    let logoImageView = UIImageView(image: UIImage(named: &quot;logo&quot;))<br>    <br>    func setupLogo() {<br>        // 圖片高度50, 起始位置60<br>        logoImageView.frame = CGRect(x: (view.bounds.width - 92) / 2, y: 60, width: 92, height: 50)<br>        logoImageView.contentMode = .scaleAspectFit<br>        logoImageView.image = logoImageView.image?.withRenderingMode(.alwaysTemplate)<br>        logoImageView.tintColor = .white<br>        view.addSubview(logoImageView)<br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*4vTJRsod17CSHM9wnGM9Dg.png" /></figure><p>在 scrollViewDidScroll 裡面設定，讓圖片可以跟著向上滑動，並且帶有逐漸透明的效果。</p><pre>func scrollViewDidScroll(_ scrollView: UIScrollView) {<br>    let offsetY = scrollView.contentOffset.y<br>    let fadeEnd: CGFloat = 50   // 滑動多少完全透明<br>    <br>    // 向上滑跟著動，向下滑固定60   <br>    if offsetY &gt; 0 {<br>        logoImageView.frame.origin.y = 60 - offsetY<br>    } else {<br>        logoImageView.frame.origin.y = 60<br>    }<br>        <br>    let alpha = max(0, min(1, 1 - offsetY / fadeEnd))<br>    logoImageView.alpha = alpha<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*MrKr_HgMdSb7ehAcgPi2AA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*fxKyYUXVLRKAwhulDh3QYA.gif" /><figcaption>(左) : APP原圖 ; (右) DEMO</figcaption></figure><blockquote><strong>2.設定第二個翻頁式的 section (popular)</strong></blockquote><p>設定 group 為橫向捲動，寬度.fractionalWidth(0.88)，這樣就不會佔滿整個螢幕寬度，然後 orthogonalScrollingBehavior = .groupPagingCentered 讓cell 可以置中顯示並且翻頁滑動，兩側可以顯示部分cell。</p><p>section.visibleItemsInvalidationHandler 可以監聽 cell 的狀態，可以在closure裡面設定動畫，當cell滑動至靠近兩側時，讓高度縮小至原本的0.9，也可以計算捲動的x距離，判斷滑到最後一個後立刻回到第一個cell的位置，就可以有無限滑動的效果。</p><pre>    // 設定popular的section<br>    private func createPopularSection() -&gt; NSCollectionLayoutSection {<br>        let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(480))<br>        let item = NSCollectionLayoutItem(layoutSize: itemSize)<br>        item.contentInsets = NSDirectionalEdgeInsets(top: 5, leading: 2, bottom: 15, trailing: 2)<br>        <br>        let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.88), heightDimension: .absolute(480))<br>        let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])<br>        <br>        let section = NSCollectionLayoutSection(group: group)<br>        section.orthogonalScrollingBehavior = .groupPagingCentered<br>        section.interGroupSpacing = 8<br>        <br>        section.visibleItemsInvalidationHandler = { (visibleItems, scrollOffset, environment) in<br>            let collectionViewCenterX = scrollOffset.x + environment.container.contentSize.width / 2<br>            let collectionViewWidth = environment.container.contentSize.width<br>            let shrinkThreshold: CGFloat = 0.6 // 超過 60% 才開始縮小<br>            // 讓兩側cell高度縮小<br>            visibleItems.forEach { item in<br>                let distanceFromCenter = abs(item.frame.midX - collectionViewCenterX)<br>                let normalizedDistance = distanceFromCenter / collectionViewWidth<br>                <br>                var scaleFactor: CGFloat = 1.0<br>                if normalizedDistance &gt; shrinkThreshold {<br>                    let adjustedDistance = (normalizedDistance - shrinkThreshold) / (1 - shrinkThreshold)<br>                    scaleFactor = 1.0 - adjustedDistance * 0.1 // 最小縮放到 0.9<br>                }<br>                <br>                item.transform = CGAffineTransform(scaleX: 1, y: scaleFactor)<br>            }<br>            <br>            // 計算滑到最後一頁的CenterX<br>            let lastCenterX = (collectionViewWidth * 0.88 + 8) * 9 + collectionViewWidth * 0.38<br>            if collectionViewCenterX &lt; collectionViewWidth/2 {<br>                let targetIndexPath = IndexPath(item: 8, section: 1) <br>                self.collectionView.scrollToItem(at: targetIndexPath, at: .centeredHorizontally, animated: false)<br>            }<br>            if collectionViewCenterX &gt; lastCenterX {<br>                let targetIndexPath = IndexPath(item: 1, section: 1)<br>                self.collectionView.scrollToItem(at: targetIndexPath, at: .centeredHorizontally, animated: false)<br>            }<br>            <br>        }<br>        <br>        return section<br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*c-g6KHq5ocBYVkUVd7ZHZg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*-A5iGkHklkwbU1b4HHRzqg.gif" /></figure><blockquote><strong>3.設定其餘3個section(theme、newRelease、recommend)</strong></blockquote><p>剩下的3個section資料，可以用一個共用的方法來設定就好。</p><pre>    // 判斷各個資料，設定section<br>    func createComposionalLayout() -&gt; UICollectionViewCompositionalLayout {<br>        UICollectionViewCompositionalLayout { [weak self] index, env in<br>            guard let self = self else { return nil }<br>            let section = sectionData[index]<br>            switch section {<br>            case .logo:<br>                return createLogoSection()<br>            case .popular:<br>                return createPopularSection()<br>            case .theme:<br>                return createSection(itemWidth: .fractionalWidth(1/3),<br>                                     itemHeight: .absolute(62),<br>                                     interItemSpacing: 10,<br>                                     groupWidth: .fractionalWidth(1),<br>                                     groupHeight: .absolute(62),<br>                                     interGroupSpacing: 10,<br>                                     sectionInset: .init(top: 8, leading: 20, bottom: 8, trailing: 20))<br>            case .newRelease:<br>                return createSection(itemWidth: .absolute(108),<br>                                     itemHeight: .absolute(152),<br>                                     interItemSpacing: 10,<br>                                     groupWidth: .absolute(108),<br>                                     groupHeight: .absolute(152),<br>                                     interGroupSpacing: 10,<br>                                     sectionInset: .init(top: 5, leading: 20, bottom: 10, trailing: 20),<br>                                     scrollBehavior: .continuous,<br>                                     headerHeight: .absolute(28))<br>            case .recommend:<br>                return createSection(itemWidth: .absolute(261),<br>                                     itemHeight: .absolute(403),<br>                                     interItemSpacing: 10,<br>                                     groupWidth: .absolute(261),<br>                                     groupHeight: .absolute(403),<br>                                     interGroupSpacing: 10,<br>                                     sectionInset: .init(top: 5, leading: 20, bottom: 95, trailing: 20),<br>                                     scrollBehavior: .continuous,<br>                                     headerHeight: .absolute(28))<br>            }<br>        }<br>    }<br><br>    // theme、newRelease、recommend 共用<br>    private func createSection(itemWidth: NSCollectionLayoutDimension,<br>                               itemHeight: NSCollectionLayoutDimension,<br>                               interItemSpacing: Double = 0,<br>                               groupWidth: NSCollectionLayoutDimension,<br>                               groupHeight: NSCollectionLayoutDimension,<br>                               interGroupSpacing: Double = 0,<br>                               sectionInset: NSDirectionalEdgeInsets = .zero,<br>                               scrollBehavior: UICollectionLayoutSectionOrthogonalScrollingBehavior = .none,<br>                               headerHeight: NSCollectionLayoutDimension? = nil) -&gt; NSCollectionLayoutSection {<br>        <br>        let itemSize = NSCollectionLayoutSize(widthDimension: itemWidth, heightDimension: itemHeight)<br>        let item = NSCollectionLayoutItem(layoutSize: itemSize)<br>        <br>        let groupSize = NSCollectionLayoutSize(widthDimension: groupWidth, heightDimension: groupHeight)<br>        let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])<br>        group.interItemSpacing = .fixed(interItemSpacing)<br>        <br>        let section = NSCollectionLayoutSection(group: group)<br>        section.orthogonalScrollingBehavior = scrollBehavior<br>        section.interGroupSpacing = interGroupSpacing<br>        section.contentInsets = sectionInset<br>        <br>        section.boundarySupplementaryItems = []<br>        if let headerHeight = headerHeight {<br>            let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: headerHeight)<br>            let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize,<br>                                                                     elementKind: UICollectionView.elementKindSectionHeader,<br>                                                                     alignment: .top)<br>            section.boundarySupplementaryItems.append(header)<br>        }<br>        <br>        return section<br>        <br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*piWxRHH9Kg_eMY4fU6TK4A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvzU1KFXLbJW7UEJPA1pnA.png" /></figure><blockquote><strong>Github:</strong></blockquote><p><a href="https://github.com/ggisfun/DisneyPlusClone.git">GitHub - ggisfun/DisneyPlusClone</a></p><blockquote><strong>Reference:</strong></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/%E6%96%B9%E4%BE%BF%E6%8E%92%E7%89%88%E7%9A%84-uicollectionviewcompositionallayout-%E5%88%9D%E9%AB%94%E9%A9%97-ab0c81ffecf6">方便排版的 UICollectionViewCompositionalLayout 初體驗</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F39cDYKeSmvs%3Fstart%3D4%26feature%3Doembed%26start%3D4&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D39cDYKeSmvs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F39cDYKeSmvs%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4aab29c3fa0f4b36edd8094197ac26a8/href">https://medium.com/media/4aab29c3fa0f4b36edd8094197ac26a8/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56dc7ab6ab2c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/28-uicollectionviewcompositionallayout%E7%B7%B4%E7%BF%92-disney-56dc7ab6ab2c">#28 UICollectionViewCompositionalLayout練習_Disney+</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[彼得潘Swift iOS 課程心得]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/%E5%BD%BC%E5%BE%97%E6%BD%98swift-ios-%E8%AA%B2%E7%A8%8B%E5%BF%83%E5%BE%97-82504df6f3e9?source=rss-d1d3fbf1cc26------2</link>
            <guid isPermaLink="false">https://medium.com/p/82504df6f3e9</guid>
            <dc:creator><![CDATA[Adam]]></dc:creator>
            <pubDate>Tue, 07 Jan 2025 15:08:51 GMT</pubDate>
            <atom:updated>2025-01-07T16:29:22.087Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.apppeterpan.com/">彼得潘的 Swift iOS App 程式設計入門</a></p><p>從上個工作離職後給自己整整放了3個月的假，本來想開始找下一份工作，後來在網路上看到彼得開的iOS課程，心想多學一個語言也挺好的就報名了。</p><p>第一堂課彼得就說了不要叫他老師，可以叫他小王子、彼得潘、Peter、<br>鬼塚、情歌王子、小潘同學，因為他希望我們之間是像朋友一樣的關係，但我必須說『鬼塚』真的是要有點年紀的人，才會知道這名子哈哈。</p><p>上課的方式可以選擇到台北的實體教室上課或線上上課，我自己是都盡量到教室去上課，因為我自己這樣會比較專心，然後課程也都會錄影上傳，所以就算上完課有不懂的地方也都不用擔心，因為可以重複看上課影片，尤其是後半段的課程我覺得比較難，所以我自己都會在找時間反覆看上課影片，只不過我都會把播放速度調整成1.5～2倍看，這樣3個小時的課2個小時就可以看完囉～～</p><p><strong><em>彼得</em></strong>的教學也會由淺入深慢慢引導，而且一些概念也會透過舉例的方式讓大家更容易理解，課程中也時不時會跟大家互動並穿插說一些冷笑話，讓整個上課過程不會感到枯燥無聊，然後上完課後你很難會不知道<strong><em>彼得</em></strong>他就是水瓶座而且很會打桌球(≧∇≦)/。</p><p>除了有趣的上課外，每個階段的課程也都有相對應的作業可以練習，畢竟寫程式還是需要實際練習才能慢慢熟悉進步，可以練習的作業有很多，所以<strong><em>彼得</em></strong>還很貼心的會把作業分成『核心任務』跟『選修任務』兩種，核心任務代表的是比較重要的作業可以優先練習，當然也可以單純選自己有興趣的主題來練習。作業練習並不是強制的，我自己也沒有每個作業都練習，也都是盡量選核心任務的來練習，在過程中就可以發現自己有哪些地方不懂或不熟悉，然後再去想辦法解決，當然也可以問<strong><em>彼得</em></strong>，雖然我大部分都是直接問AI，畢竟現在的AI真的很方便啊。</p><p>還有一個很重要的事，就是作業要發表在Medium上面，一開始不太知道要怎麼寫，因為以前沒這樣寫過，所以我都是參考以前學長姐寫的文章，然後模仿著寫，雖然要花很多時間因為寫很慢的關係，但是寫多了就會慢慢的越寫越順，最重要的是可以透過在Medium上面寫文章，讓自己重新審視一次自己寫的作業，等於加深自己的印象，而且如果之後想要複習就可以馬上回來看，總之寫Medium好處多多啊！</p><p>總之很開心自己報名了這門課，如果想學寫iOS APP的話，<strong><em>彼得</em></strong>的課真的很值得來上，不過程式能力畢竟不可能一下子就變好， 最重要的還是要自己花時間多多練習，而且就算課程已經結束了，之後有問題還是可以問<strong><em>彼得，</em></strong>他仍然會很樂意的幫助你。感謝<strong><em>彼得</em></strong>帶我進入Swift 的世界，雖然不懂的還很多，希望自己之後可以持續努力的學習，讓自己再多進步一點。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nLyocgVbVV2whJufwNBd_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rbriXaHKg71ayhaKs8RExg.png" /></figure><p><a href="https://www.apppeterpan.com/">彼得潘的 Swift iOS App 程式設計入門</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82504df6f3e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/%E5%BD%BC%E5%BE%97%E6%BD%98swift-ios-%E8%AA%B2%E7%A8%8B%E5%BF%83%E5%BE%97-82504df6f3e9">彼得潘Swift iOS 課程心得</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[#27 Google/Facebook/Apple登入]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/27-google-facebook-apple%E7%99%BB%E5%85%A5-30bce119cf0f?source=rss-d1d3fbf1cc26------2</link>
            <guid isPermaLink="false">https://medium.com/p/30bce119cf0f</guid>
            <dc:creator><![CDATA[Adam]]></dc:creator>
            <pubDate>Tue, 26 Nov 2024 09:27:38 GMT</pubDate>
            <atom:updated>2024-11-27T02:11:18.192Z</atom:updated>
            <content:encoded><![CDATA[<p>練習實作 Google、Facebook和Apple的登入功能</p><blockquote><strong>DEMO:</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*VtxL4TmQf2WjnJD_mxFJLg.gif" /></figure><p>大致的步驟～</p><h4>Google登入：</h4><ol><li>安裝 Google 的 SDK。</li><li>到Google的開發網站，建立專案並輸入Xcode專案的Bundle ID 綁定。</li><li>在Xcode專案的 Info.plist、AppDelegate加入Google登入需要的資訊和程式碼。</li><li>加入Google的登入按鈕，建立對應的方法。</li></ol><h4>Facebook登入：</h4><ol><li>安裝 Facebook 的 SDK</li><li>到Facebook的開發網站，建立專案並輸入Xcode專案的Bundle ID 綁定。</li><li>在Xcode專案的 Info.plist、AppDelegate和SceneDelegate加入Facebook登入需要的資訊和程式碼。</li><li>在Xcode專案的 Signing &amp; Capabilities，點選＋Capability 加入 Keychain Sharing。</li><li>加入Facebook的登入按鈕，建立對應的方法。</li></ol><h4>Apple登入：</h4><ol><li>在Xcode專案的 Signing &amp; Capabilities，點選＋Capability 加入 Sign in with Apple。</li><li>加入Apple 的登入按鈕，建立對應的方法。</li></ol><blockquote><strong>安裝Google 和 Facebook SDK</strong></blockquote><p>Google URL: <a href="https://github.com/google/GoogleSignIn-iOS">github.com/google/GoogleSignIn-iOS</a></p><p>Facebook URL: <a href="https://github.com/facebook/facebook-ios-sdk">github.com/facebook/facebook-ios-sdk</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R1zFrHzLvWy9hRxldM-H0Q.png" /></figure><blockquote><strong>到 Google 和 Facebook的開發者網站建立專案：</strong></blockquote><ul><li><a href="https://developers.google.com/identity/sign-in/ios/start-integrating?hl=zh-tw">開始使用 iOS 和 macOS 適用的 Google 登入功能 | Authentication | Google for Developers</a></li><li><a href="https://developers.facebook.com/">Social technologies | Meta for Developers</a></li></ul><p>建立時需要輸入Xcode的Bundle ID綁定</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zErRE5JzoQlxe0i65ceTNg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_bTileOhliZxPS_GqrRAJg.png" /><figcaption>(左)Google, (右)Facebook</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVuex-Kf3yGHWvQ6AUXc6w.png" /></figure><p>照著官網的步驟創建好專案後，可以在各自的控制台看到需要的資訊。</p><p>Google =&gt; 用戶端編號、iOS網址通訊協定</p><p>Facebook =&gt; 應用程式編號、用戶端權杖</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nCnE2ElKKD8A_rSY9X2yUA.png" /><figcaption>Google</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*74J7RRsGLPfy5xT-ipPiKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cORycj2tiIh8i1xDdZYCuw.png" /><figcaption>Facebook</figcaption></figure><blockquote><strong>在 Info.plist 裡加入上面的資訊</strong></blockquote><p>點選 Info.plist 右鍵，用Source Code 方式開啟。</p><pre>    &lt;key&gt;CFBundleURLTypes&lt;/key&gt;<br>    &lt;array&gt;<br>        &lt;!-- Facebook URL Scheme --&gt;<br>        &lt;dict&gt;<br>            &lt;key&gt;CFBundleURLSchemes&lt;/key&gt;<br>            &lt;array&gt;<br>                &lt;string&gt;fb應用程式編號&lt;/string&gt;開頭fb+應用程式編號<br>            &lt;/array&gt;<br>        &lt;/dict&gt;<br>        &lt;!-- Google URL Scheme --&gt;<br>        &lt;dict&gt;<br>            &lt;key&gt;CFBundleURLSchemes&lt;/key&gt;<br>            &lt;array&gt;<br>                &lt;string&gt;iOS網址通訊協定&lt;/string&gt;<br>            &lt;/array&gt;<br>        &lt;/dict&gt;<br>    &lt;/array&gt;<br>    <br>    &lt;!-- Facebook Configuration --&gt;<br>    &lt;key&gt;FacebookAppID&lt;/key&gt;<br>    &lt;string&gt;應用程式編號&lt;/string&gt;<br>    &lt;key&gt;FacebookClientToken&lt;/key&gt;<br>    &lt;string&gt;用戶端權杖&lt;/string&gt;<br>    &lt;key&gt;FacebookDisplayName&lt;/key&gt;<br>    &lt;string&gt;LoginDemo&lt;/string&gt;<br>    &lt;key&gt;LSApplicationQueriesSchemes&lt;/key&gt;<br>    &lt;array&gt;<br>        &lt;string&gt;fbapi&lt;/string&gt;<br>        &lt;string&gt;fb-messenger-share-api&lt;/string&gt;<br>    &lt;/array&gt;<br>    <br>    &lt;!-- Google Configuration --&gt;<br>    &lt;key&gt;GIDClientID&lt;/key&gt;<br>    &lt;string&gt;用戶端編號&lt;/string&gt;</pre><blockquote><strong>AppDelegate：</strong></blockquote><p>import FacebookCore &amp; GoogleSignIn</p><pre>import UIKit<br>import FacebookCore<br>import GoogleSignIn<br><br>@main<br>class AppDelegate: UIResponder, UIApplicationDelegate {<br>    <br>    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {<br>        <br>        // 初始化 Facebook SDK<br>        ApplicationDelegate.shared.application(<br>            application,<br>            didFinishLaunchingWithOptions: launchOptions<br>        )<br>        <br>        // 恢復 Google 登錄狀態<br>        GIDSignIn.sharedInstance.restorePreviousSignIn { user, error in<br>            if let error = error {<br>                print(&quot;Google 登錄恢復失敗: \(error.localizedDescription)&quot;)<br>                // 處理登出狀態的邏輯<br>            } else if let user = user {<br>                print(&quot;Google 登錄恢復成功，用戶: \(user.profile?.email ?? &quot;無法獲取 email&quot;)&quot;)<br>                // 處理登錄狀態的邏輯<br>            }<br>        }<br>        <br>        return true<br>    }<br>    <br>    func application(<br>        _ app: UIApplication,<br>        open url: URL,<br>        options: [UIApplication.OpenURLOptionsKey : Any] = [:]<br>    ) -&gt; Bool {<br>        <br>        // Google Sign-In 回調<br>        if GIDSignIn.sharedInstance.handle(url) {<br>            return true<br>        }<br>        <br>        // Facebook 登錄回調<br>        if ApplicationDelegate.shared.application(app, open: url, options: options) {<br>            return true<br>        }<br>        <br>        return false<br>    }<br><br>}</pre><blockquote><strong>SceneDelegate：</strong></blockquote><p>import FacebookCore</p><p>加入 func scene(_ scene: UIScene, openURLContexts URLContexts: Set&lt;UIOpenURLContext&gt;)</p><pre>import UIKit<br>import FacebookCore<br><br>class SceneDelegate: UIResponder, UIWindowSceneDelegate {<br>    <br>    func scene(_ scene: UIScene, openURLContexts URLContexts: Set&lt;UIOpenURLContext&gt;) {<br>        guard let url = URLContexts.first?.url else {<br>            return<br>        }<br><br>        ApplicationDelegate.shared.application(<br>            UIApplication.shared,<br>            open: url,<br>            sourceApplication: nil,<br>            annotation: [UIApplication.OpenURLOptionsKey.annotation]<br>        )<br>    }<br><br>}</pre><blockquote><strong>加入 Keychain Sharing 和 Sign in with Apple</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MQN91_sLEjeqEqULAPHSKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISuX_tjL1-yKSQwrghffcA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L2xKc3UvH1uid58gd2ztpw.png" /></figure><p>加入後會顯示在下面</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*sEj4St9pTnY3vJXzTdN90w.png" /></figure><blockquote><strong>加入Google 、Facebook 和 Apple 的登入按鈕，建立對應的方法</strong></blockquote><p>Google、Facebook 的SDK裡，都有自己的按鈕類別可以使用，Google 是GIDSignInButton，Facebook 是FBLoginButton，但我這邊為了讓三個按鈕看起來比較整齊所以自己添加按鈕並拉IBAction。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*IhWZuUHaTfR0yw_7A9VOJQ.png" /></figure><pre>import UIKit<br>import FacebookCore<br>import FacebookLogin<br>import GoogleSignIn<br>import AuthenticationServices<br><br>class ViewController: UIViewController {<br><br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>    }<br><br>    // Facebook 登入按鈕的動作<br>    @IBAction func loginByFacebookButton(_ sender: UIButton) {<br>        let loginManager = LoginManager()<br>        // 設定 Facebook 登入的權限、追蹤選項及 nonce<br>        guard let configuration = LoginConfiguration(permissions: [&quot;public_profile&quot;, &quot;email&quot;], tracking: .limited, nonce: &quot;123&quot;) else { return }<br>        <br>        // 執行 Facebook 登入<br>        loginManager.logIn(configuration: configuration) { result in<br>            switch result {<br>            case .cancelled, .failed:<br>                // 若取消或失敗，直接返回<br>                return<br>            case .success:<br>                // 成功登入後，取得使用者資料<br>                let id = Profile.current?.userID<br>                let name = Profile.current?.name<br>                let email = Profile.current?.email<br>                <br>                print(&quot;id:\(String(describing: id))&quot;) // 使用者 ID<br>                print(&quot;name:\(String(describing: name))&quot;) // 使用者名稱<br>                print(&quot;email:\(String(describing: email))&quot;) // 使用者電子郵件<br>            }<br>        }<br>    }<br>    <br>    // Google 登入按鈕的動作<br>    @IBAction func loginByGoogleButton(_ sender: UIButton) {<br>        // 使用 Google 登入<br>        GIDSignIn.sharedInstance.signIn(withPresenting: self) { signInResult, error in<br>            guard error == nil else { return } // 若有錯誤則返回<br>            guard let result = signInResult else { return } // 確保登入結果不為空<br>            <br>            // 登入成功，取得使用者資料<br>            let user = result.user<br>            let id = user.userID<br>            let name = user.profile?.name<br>            let email = user.profile?.email<br>            <br>            print(&quot;id:\(String(describing: id))&quot;) // 使用者 ID<br>            print(&quot;name:\(String(describing: name))&quot;) // 使用者名稱<br>            print(&quot;email:\(String(describing: email))&quot;) // 使用者電子郵件<br>        }<br>    }<br>    <br>    // Apple 登入按鈕的動作<br>    @IBAction func loginByAppleButton(_ sender: UIButton) {<br>        // 初始化 Apple 登入請求<br>        let appleProvider = ASAuthorizationAppleIDProvider()<br>        let request = appleProvider.createRequest()<br>        request.requestedScopes = [.email, .fullName] // 請求電子郵件和全名<br>        let authorizationController = ASAuthorizationController(authorizationRequests: [request])<br>        authorizationController.delegate = self<br>        authorizationController.presentationContextProvider = self<br>        authorizationController.performRequests() // 執行請求<br>    }<br>}<br><br>// 擴展以處理 Apple 登入的相關代理方法<br>extension ViewController: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding {<br>    // 提供展示 Apple 登入 UI 的視窗<br>    func presentationAnchor(for controller: ASAuthorizationController) -&gt; ASPresentationAnchor {<br>        return view.window!<br>    }<br>    <br>    // 登入失敗時的回調<br>    func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: any Error) {<br>        print(error.localizedDescription) // 打印錯誤訊息<br>    }<br>    <br>    // 登入成功時的回調<br>    func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {<br>        if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {<br>            // 取得使用者資料<br>            let id = appleIDCredential.user<br>            let fullName = appleIDCredential.fullName<br>            let email = appleIDCredential.email<br>            <br>            print(&quot;id:\(String(describing: id))&quot;) // 使用者 ID<br>            print(&quot;fullName:\(String(describing: fullName))&quot;) // 使用者全名<br>            print(&quot;email:\(String(describing: email))&quot;) // 使用者電子郵件<br>        }<br>    }<br>}</pre><blockquote><strong>Github:</strong></blockquote><p><a href="https://github.com/ggisfun/LoginDemo.git">GitHub - ggisfun/LoginDemo</a></p><blockquote><strong>Reference:</strong></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/%E5%AF%A6%E4%BD%9C-ios-app-%E7%9A%84-facebook-%E7%99%BB%E5%85%A5%E5%8A%9F%E8%83%BD-96c981d482cc">實作 iOS App 的 Facebook 登入功能</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FV_zBQ9AQv3s%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DV_zBQ9AQv3s&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FV_zBQ9AQv3s%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/60a718a2d48b4bc4b512236948ee9dae/href">https://medium.com/media/60a718a2d48b4bc4b512236948ee9dae/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FPgRimATM0k8%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPgRimATM0k8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FPgRimATM0k8%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d658b8716107421c3e153b085d79f4c/href">https://medium.com/media/7d658b8716107421c3e153b085d79f4c/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fg1yGmOQBbg4%3Fstart%3D190%26feature%3Doembed%26start%3D190&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dg1yGmOQBbg4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fg1yGmOQBbg4%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/15ebda6a7c0c8593ece85342ffd5a243/href">https://medium.com/media/15ebda6a7c0c8593ece85342ffd5a243/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30bce119cf0f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/27-google-facebook-apple%E7%99%BB%E5%85%A5-30bce119cf0f">#27 Google/Facebook/Apple登入</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[#26 滑雪場介紹APP]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/26-%E6%BB%91%E9%9B%AA%E5%A0%B4%E4%BB%8B%E7%B4%B9app-76809cc1b31e?source=rss-d1d3fbf1cc26------2</link>
            <guid isPermaLink="false">https://medium.com/p/76809cc1b31e</guid>
            <dc:creator><![CDATA[Adam]]></dc:creator>
            <pubDate>Wed, 20 Nov 2024 07:40:52 GMT</pubDate>
            <atom:updated>2024-11-20T08:27:57.555Z</atom:updated>
            <content:encoded><![CDATA[<p>冬季要來臨了，去年跟朋友去日本的野澤溫泉滑雪場滑雪過，發現滑雪是個很好玩的運動啊！雖然過程中會一直摔倒，但是在雪地裡就算摔倒也是一件很開心的事啊～～今年朋友又約説要去日本滑雪，所以最近一直在做功課，查了一些日本滑雪場的資訊，研究要去哪裡滑，就順便把這些資料拿來寫APP練習囉！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*GdwnpyzxQJjUkh_onS3j6A.gif" /></figure><blockquote><strong>DEMO:</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*O7T8zz4L88xdhlP1oPHj7w.gif" /></figure><p>整個架構就用TabBarController顯示”雪場列表”跟”收藏列表”兩個分頁，然後用TableView 把資料顯示出來，TableViewCell就用XIB建立，然後讓兩個分頁共用，雪場資料也是用TableView來顯示。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2tEr8MsU5IlZ4RoOfgFGIA.png" /></figure><p>日本大大小小的雪場總數好像有四、五百個，超級多的，我只能把一些我知道的或是我覺得比較有名的滑雪場列出來，然後去查這些雪場的資料。</p><p><a href="https://surfsnow.jp/">国内最大級のスキー場・積雪情報サイト ‐ SURF&amp;SNOW</a></p><p>這是一個可以查到很多日本滑雪場介紹的網站，裡面的介紹的資料很多，有天氣、雪道數、坡度等等…，最近都在這網站逛來逛去。</p><p><a href="https://skimap.org/">https://skimap.org/</a></p><p>這是一個提供全球滑雪場地圖的網站，可以免費瀏覽和下載這些地圖。把想介紹的雪場資料整理好後，請AI幫忙整理成json資料在上傳到github～～</p><p><a href="https://raw.githubusercontent.com/ggisfun/SkiResortJapan/main/SkiResortJapan.json">https://raw.githubusercontent.com/ggisfun/SkiResortJapan/main/SkiResortJapan.json</a></p><p>然後建立接收資料的 Struct 和 抓取資料的方法 fetchSkiResorts並顯示TableView上。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*B4P0zPZoetSiLNcQYV-pOQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8TLaELiMUUsPSa68skH9lg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQAktqLpQER5i6E4C8qjDA.png" /></figure><p>雪場地圖的圖片用第三方套件KingFisher顯示。</p><p>雪場的雪道有分成初級、中級、高級三種，而雪道的構成又有分成壓雪和未壓雪兩種，用圓餅圖來顯示這兩種資料。</p><p>把繪製圓餅圖單獨寫成一個func，傳入四個參數，要畫的view、label名稱、要顯示的顏色和百分比資料，因為有設定AutoLayout的關係，所以在viewDidLayoutSubviews裡面執行繪製圓餅圖的方法。</p><pre>    @IBOutlet weak var trailDifficultyView: UIView! //要畫圓餅圖的view<br>    @IBOutlet weak var trailCompositionView: UIView!//要畫圓餅圖的view<br><br>    var difficultyLabels: [String] = [&quot;初級&quot;, &quot;中級&quot;, &quot;高級&quot;]<br>    var compositionLabels: [String] = [&quot;壓雪&quot;, &quot;非壓雪&quot;]<br><br>    let difficultyColors = [<br>        UIColor.systemGreen.withAlphaComponent(0.6),  // 綠色<br>        UIColor.systemBlue.withAlphaComponent(0.6),   // 藍色<br>        UIColor.systemRed.withAlphaComponent(0.6)     // 紅色<br>    ]<br>    let compositionColors = [<br>        UIColor.systemYellow.withAlphaComponent(0.6), //黃色<br>        UIColor.systemOrange.withAlphaComponent(0.6)  //橘色<br>    ]<br><br>    override func viewDidLayoutSubviews() {<br>        let difficultyPercent = [<br>            skiResortInfo.trailDifficulty.beginner,<br>            skiResortInfo.trailDifficulty.intermediate,<br>            skiResortInfo.trailDifficulty.advanced<br>        ]<br>        <br>        let compositionPercent = [<br>            skiResortInfo.trailComposition.groomed,<br>            skiResortInfo.trailComposition.ungroomed<br>        ]<br>        <br>        drawPieChart(on: trailDifficultyView, with: difficultyPercent, labels: difficultyLabels, colors: difficultyColors)<br>        drawPieChart(on: trailCompositionView, with: compositionPercent, labels: compositionLabels, colors: compositionColors)<br>    }<br><br>    //繪製圓餅圖<br>    func drawPieChart(on view: UIView, with data: [Double], labels: [String], colors: [UIColor]) {<br>        let total = data.reduce(0, +)<br>        var startAngle: CGFloat = -.pi / 2<br>        <br>        for (index, value) in data.enumerated() {<br>            let endAngle = startAngle + CGFloat(value / total) * 2 * .pi<br>            let path = UIBezierPath()<br>            path.move(to: CGPoint(x: view.bounds.midX, y: view.bounds.midY))<br>            path.addArc(withCenter: CGPoint(x: view.bounds.midX, y: view.bounds.midY),<br>                        radius: (view.bounds.width - 4) / 2,<br>                        startAngle: startAngle,<br>                        endAngle: endAngle,<br>                        clockwise: true)<br>            <br>            let shapeLayer = CAShapeLayer()<br>            shapeLayer.path = path.cgPath<br>            shapeLayer.fillColor = colors[index % colors.count].cgColor // 使用固定顏色<br>            <br>            view.layer.addSublayer(shapeLayer)<br>            <br>            // 計算標籤位置<br>            let middleAngle = (startAngle + endAngle) / 2<br>            let radius = view.bounds.width / 2 * 0.6 // 調整半徑以將標籤放置在內圈<br>            let labelX = view.bounds.midX + radius * cos(middleAngle)<br>            let labelY = view.bounds.midY + radius * sin(middleAngle)<br>            <br>            let label = UILabel()<br>            label.textColor = .black<br>            label.text = &quot;\(labels[index])\n\(Int(value))%&quot; // 格式化顯示名稱和數值<br>            label.font = UIFont.systemFont(ofSize: 14)<br>            label.textAlignment = .center<br>            label.numberOfLines = 0 // 設置標籤為多行<br>            label.sizeToFit()<br>            label.center = CGPoint(x: labelX, y: labelY)<br>            <br>            // 檢查標籤是否超出邊界，調整位置或縮小文字<br>            if label.frame.maxX &gt; view.bounds.width || label.frame.maxY &gt; view.bounds.height {<br>                label.font = UIFont.systemFont(ofSize: 12)<br>                label.sizeToFit()<br>                label.center = CGPoint(x: labelX, y: labelY)<br>            }<br>            <br>            view.addSubview(label)<br>            <br>            startAngle = endAngle<br>        }<br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i9shHOP4jsVO7zeaPp5P1g.png" /></figure><p>在畫面右上方加入兩個Bar Button Item，可以開啟雪場官網跟加入收藏，加入收藏則是直接用一個陣列然後使用UserDefault儲存起來。</p><pre>    private func configureItems() {<br>        let heartImageName = isFavorite ? &quot;heart.fill&quot; : &quot;heart&quot;<br>        heartButton = UIBarButtonItem(image: UIImage(systemName: heartImageName), style: .done, target: self, action: #selector(toggleFavorite))<br>        houseButton = UIBarButtonItem(image: UIImage(systemName: &quot;house.fill&quot;), style: .plain, target: self, action: #selector(openWebsite))<br>        heartButton.tintColor = isFavorite ? UIColor.systemPink : UIColor.black<br>        houseButton.tintColor = UIColor.black<br>        navigationItem.rightBarButtonItems = [heartButton, houseButton]<br>    }<br><br>    // 加入＆移除 收藏<br>    @objc func toggleFavorite() {<br>        if !isFavorite {<br>            if !favoriteArray.contains(skiResortInfo.name) {<br>                isFavorite.toggle()<br>                updateHeartButtonImage()<br>                <br>                favoriteArray.append(skiResortInfo.name)<br>                favoriteList.append(skiResortInfo)<br>                <br>                delegate?.infoTableViewController(self, didUpdateFavoriteArray: favoriteArray)<br>                delegate?.infoTableViewController(self, didUpdateFavoriteList: favoriteList)<br>                <br>                DispatchQueue.main.async {<br>                    SkiResort.saveFavorites(self.favoriteArray)<br>                }<br>                <br>                showAlert(title: &quot;已加入收藏&quot;, message: nil, autoDismiss: true)<br>            }<br>        } else {<br>            let controller = UIAlertController(title: &quot;從收藏中移除嗎？&quot;, message: nil, preferredStyle: .alert)<br>            let confirmAction = UIAlertAction(title: &quot;確定&quot;, style: .default) { _ in<br>                self.isFavorite.toggle()<br>                self.updateHeartButtonImage()<br>                <br>                self.favoriteArray.removeAll(where: { $0 == self.skiResortInfo.name })<br>                self.favoriteList.removeAll(where: { $0.name == self.skiResortInfo.name })<br>                <br>                self.delegate?.infoTableViewController(self, didUpdateFavoriteArray: self.favoriteArray)<br>                self.delegate?.infoTableViewController(self, didUpdateFavoriteList: self.favoriteList)<br>                <br>                DispatchQueue.main.async {<br>                    SkiResort.saveFavorites(self.favoriteArray)<br>                }<br>                <br>                self.showAlert(title: &quot;已移除收藏&quot;, message: nil, autoDismiss: true)<br>            }<br>            let cancelAction = UIAlertAction(title: &quot;取消&quot;, style: .cancel)<br>            controller.addAction(confirmAction)<br>            controller.addAction(cancelAction)<br>            present(controller, animated: true)<br>        }<br>        <br>    }<br>    <br>    // 更新收藏的圖片<br>    func updateHeartButtonImage() {<br>        let updatedImageName = isFavorite ? &quot;heart.fill&quot; : &quot;heart&quot;<br>        heartButton.tintColor = isFavorite ? UIColor.systemPink : UIColor.black<br>        heartButton.image = UIImage(systemName: updatedImageName)<br>    }<br>    <br>    func showAlert(title: String, message: String?, autoDismiss: Bool = false) {<br>        let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)<br>        let okAction = UIAlertAction(title: &quot;好的&quot;, style: .default)<br>        controller.addAction(okAction)<br>        <br>        present(controller, animated: true) {<br>            if autoDismiss {<br>                DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {<br>                    controller.dismiss(animated: true)<br>                }<br>            }<br>        }<br>    }<br>    <br>    // 開啟雪場官網<br>    @objc private func openWebsite() {<br>        if let url = URL(string: skiResortInfo.websiteUrl) {<br>            UIApplication.shared.open(url, options: [:], completionHandler: nil)<br>        }<br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*nbsZmnQ8M-TwHHgx08Pd-A.gif" /></figure><p>建立 ImageZoomViewController ，加入scrollView 和 imageView 讓圖片可以縮放。</p><p>在圖片上加入點擊的手勢功能，點圖片後呼叫方法 didTapMapImageView，並在方法裡present ImageZoomViewController，讓圖片可以另外顯示出來並且縮放。</p><pre>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        <br>        // 加入點擊的手勢功能<br>        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapMapImageView))<br>        mapImageView.isUserInteractionEnabled = true<br>        mapImageView.addGestureRecognizer(tapGesture)<br>        <br>    }<br><br>    @objc func didTapMapImageView() {<br>        let zoomViewController = ImageZoomViewController()<br>        zoomViewController.image = mapImageView.image<br>        zoomViewController.modalPresentationStyle = .fullScreen<br>        present(zoomViewController, animated: true)<br>    }<br><br><br>class ImageZoomViewController: UIViewController, UIScrollViewDelegate {<br>   <br>    var image: UIImage?<br>    private let scrollView = UIScrollView()<br>    private let imageView = UIImageView()<br>    <br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        // 設置背景顏色為黑色<br>        view.backgroundColor = .black<br>        <br>        scrollView.delegate = self<br>        scrollView.frame = view.bounds<br>        scrollView.autoresizingMask = [.flexibleWidth, .flexibleHeight] // 設置自動調整寬度和高度<br>        scrollView.minimumZoomScale = 1.0<br>        scrollView.maximumZoomScale = 4.0<br>        <br>        view.addSubview(scrollView)<br>        <br>        imageView.image = image<br>        imageView.contentMode = .scaleAspectFit<br>        imageView.frame = scrollView.bounds<br>        scrollView.addSubview(imageView)<br>        <br>        // 添加點擊手勢，用於關閉Controller<br>        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissZoomView))<br>        view.addGestureRecognizer(tapGesture)<br>    }<br>    <br>    // 點擊手勢的觸發方法，關閉Controller<br>    @objc func dismissZoomView() {<br>        dismiss(animated: true)<br>    }<br>    <br>    // MARK: - UIScrollViewDelegate<br>    // 指定可進行縮放的視圖<br>    func viewForZooming(in scrollView: UIScrollView) -&gt; UIView? {<br>        return imageView<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*2spm2Zt0FwJGxF5b4lO8yw.gif" /></figure><blockquote><strong>Github:</strong></blockquote><p><a href="https://github.com/ggisfun/SkiResortInJapan.git">GitHub - ggisfun/SkiResortInJapan</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76809cc1b31e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/26-%E6%BB%91%E9%9B%AA%E5%A0%B4%E4%BB%8B%E7%B4%B9app-76809cc1b31e">#26 滑雪場介紹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>
        <item>
            <title><![CDATA[#25 xib練習＆串接第三方天氣API]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/25-xib%E7%B7%B4%E7%BF%92-%E4%B8%B2%E6%8E%A5%E7%AC%AC%E4%B8%89%E6%96%B9%E5%A4%A9%E6%B0%A3api-25a52e9ecd15?source=rss-d1d3fbf1cc26------2</link>
            <guid isPermaLink="false">https://medium.com/p/25a52e9ecd15</guid>
            <dc:creator><![CDATA[Adam]]></dc:creator>
            <pubDate>Tue, 29 Oct 2024 05:51:01 GMT</pubDate>
            <atom:updated>2025-03-29T03:05:24.327Z</atom:updated>
            <content:encoded><![CDATA[<p>練習使用 xib 製作TableView Cell &amp; CollectionView Cell，還有串接第三方API。</p><blockquote><strong>DEMO:</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iTRQdkcxZNGyQZ06jV6LWw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JjOKGImBXD-p1PaEu7Ukaw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*G6NnlkQjpjM9L_mOMoA6lg.gif" /></figure><p>建立各縣市的按鈕選單。</p><pre>    @IBOutlet weak var cityButton: UIButton!<br><br>    let cities: [String: String] = [<br>        &quot;台北市&quot;: &quot;Taipei City&quot;,<br>        &quot;新北市&quot;: &quot;New Taipei City&quot;,<br>        ...<br>        ...<br>        ...<br>        &quot;金門縣&quot;: &quot;Kinmen County&quot;,<br>        &quot;連江縣&quot;: &quot;Lienchiang County&quot;<br>    ]<br><br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        // Do any additional setup after loading the view.<br>        <br>        let cityMenu = UIMenu(title: &quot;請選擇區域&quot;, options: .displayInline, children: createMenuActions())<br>        cityButton.menu = cityMenu<br>        cityButton.showsMenuAsPrimaryAction = true<br>    }<br><br>    // 建立按鈕選單<br>    func createMenuActions() -&gt; [UIAction] {<br>        var actions: [UIAction] = []<br>        let sortedCities = cities.sorted { $0.key &lt; $1.key }<br>        for city in sortedCities {<br>            let action = UIAction(title: city.key, handler: { _ in<br>                self.cityButton.setTitle(&quot;當前區域: \(city.key)&quot;, for: .normal)<br>                self.callWeatherAPI(city: city.value)<br>            })<br>            actions.append(action)<br>        }<br>        return actions<br>    }</pre><p>因為要練習使用xib，創建cell 類別時要勾選 Also create XIB file。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*WdiEF0OMyKO4zRjQk86MjA.png" /></figure><p>把要顯示的元件 label 和 imageView 放進cell ，並設定約束條件，程式裡要記得用.register 註冊cell。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KpdUVLYmlaggCYH4eZkppQ.png" /></figure><pre>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        // Do any additional setup after loading the view.<br>        <br>        //顯示當天每小時溫度<br>        tableView.register(HourlyTableViewCell.nib(), forCellReuseIdentifier: HourlyTableViewCell.identifier)<br>        //顯示未來14天預測<br>        tableView.register(WeatherTableViewCell.nib(), forCellReuseIdentifier: WeatherTableViewCell.identifier)<br>        <br>    }<br><br><br><br>class WeatherTableViewCell: UITableViewCell {<br>    static let identifier = &quot;WeatherTableViewCell&quot;<br>    <br>    static func nib() -&gt; UINib {<br>        return UINib(nibName: &quot;WeatherTableViewCell&quot;, bundle: nil)<br>    }<br>}<br><br>class HourlyTableViewCell: UITableViewCell { <br>    static let identifier = &quot;HourlyTableViewCell&quot;<br>    <br>    static func nib() -&gt; UINib {<br>        return UINib(nibName: &quot;HourlyTableViewCell&quot;, bundle: nil)<br>    }    <br>}</pre><p>表格的第一個cell 要用CollectionView Cell 顯示每小時溫度，所以要再建立一個CollectionView Cell 的 xib ，並在 TableView Cell 裡面註冊，設置delegate &amp; data source &amp; delegateFlowLayout。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*zt2TtTlxLNQ6VRVufshcFQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Kxt9zOHblaSTFhIgkegRqg.png" /></figure><pre>import UIKit<br><br>class HourlyTableViewCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {<br><br>    @IBOutlet var collectionView: UICollectionView!<br>    var models = [Hour]()// 每小時資料<br>     <br>    static let identifier = &quot;HourlyTableViewCell&quot;<br>    <br>    static func nib() -&gt; UINib {<br>        return UINib(nibName: &quot;HourlyTableViewCell&quot;, bundle: nil)<br>    }<br>    <br>    override func awakeFromNib() {<br>        super.awakeFromNib()<br>        // 註冊CollectionViewCell<br>        collectionView.register(WeatherCollectionViewCell.nib(), forCellWithReuseIdentifier: WeatherCollectionViewCell.identifier)<br>        collectionView.delegate = self<br>        collectionView.dataSource = self<br>    }<br><br>    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {<br>        models.count<br>    }<br>    <br>    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {<br>        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: WeatherCollectionViewCell.identifier, for: indexPath) as! WeatherCollectionViewCell<br>        cell.configure(with: models[indexPath.row])<br>        return cell<br>    }<br><br>}</pre><p>CollectionView 的 Scroll Direction 要改成 Horizontal 方向，讓顯示的cell 可以水平滑動。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*zOKuYemd8-96Ji85qfORWA.png" /></figure><p>可以練習串接的天氣API其實有很多個，選了一個感覺比較少見的<strong>Visual Crossing Weather API </strong>來練習，在官網申請金鑰後，按照說明文檔發出請求，並把返回的資料轉成json格式顯示。</p><p>返回的資料很多，需要顯示的資料是</p><p>當前溫度 =&gt; currentConditions</p><p>當天每小時 =&gt; hours : [24 items]</p><p>未來15天預測 =&gt; days : [15 items]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*-qF8y18KpyRxzLLfgjsWJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*bmsGhlNOKYPaL1zCb28JVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*eULbuGhq2K30MDxzat69cA.png" /></figure><p>建立接收資料的<strong>struct。</strong></p><pre>import Foundation<br><br>struct WeatherResponse: Codable {<br>    let days: [Day]<br>    let currentConditions: CurrentConditions<br>}<br>//未來15天預測資料<br>struct Day: Codable {<br>    let datetime: String<br>    let icon: String<br>    let tempmax: Double<br>    let tempmin: Double<br>    let temp: Double<br>    let precipprob: Double<br>    let hours: [Hour]<br>}<br>//每小時資料<br>struct Hour: Codable {<br>    let datetime: String<br>    let temp: Double<br>    let icon: String<br>}<br>//當前溫度資料<br>struct CurrentConditions: Codable {<br>    let datetime: String<br>    let temp: Double<br>    let precipprob: Double<br>    let windspeed: Double<br>    let icon: String<br>}</pre><p>URLSession 抓取資料。</p><pre>    enum WeatherError: Error {<br>        case invalidURL<br>        case networkError(Error)<br>        case decodingError(Error)<br>        case noData<br>        case invalidResponse<br>    }<br>    <br>    func fetchWeatherData(for city: String, completion: @escaping (Result&lt;WeatherResponse, WeatherError&gt;) -&gt; Void) {<br>        <br>        let urlString = &quot;https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/\(city)?key=\(apiKey)&amp;unitGroup=metric&amp;contentType=json&quot;<br>        <br>        guard let url = URL(string: urlString) else {<br>            completion(.failure(.invalidURL))<br>            return<br>        }<br>        <br>        let task = URLSession.shared.dataTask(with: url) { data, response, error in<br>            if let error = error {<br>                completion(.failure(.networkError(error)))<br>                return<br>            }<br>            <br>            if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode != 200 {<br>                completion(.failure(.invalidResponse))<br>                return<br>            }<br>            <br>            guard let data = data else {<br>                completion(.failure(.noData))<br>                return<br>            }<br>            <br>            do {<br>                let decoder = JSONDecoder()<br>                let weatherResponse = try decoder.decode(WeatherResponse.self, from: data)<br>                completion(.success(weatherResponse))<br>            } catch {<br>                completion(.failure(.decodingError(error)))<br>            }<br>        }<br>        <br>        task.resume()<br>    }</pre><blockquote><strong>Github:</strong></blockquote><p><a href="https://github.com/ggisfun/MyWeatherApp.git">GitHub - ggisfun/MyWeatherApp</a></p><blockquote><strong>Reference:</strong></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%E6%95%99%E5%AE%A4/ios-weather-app-part2-%E4%B8%B2%E6%8E%A5openweathermap-5921ee4d903e">[iOS] Weather App-Part2.串接OpenWeatherMap</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FGFcBE4JxiWs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DGFcBE4JxiWs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FGFcBE4JxiWs%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/73a40187aa99b3a974c36507c1166aee/href">https://medium.com/media/73a40187aa99b3a974c36507c1166aee/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25a52e9ecd15" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/25-xib%E7%B7%B4%E7%BF%92-%E4%B8%B2%E6%8E%A5%E7%AC%AC%E4%B8%89%E6%96%B9%E5%A4%A9%E6%B0%A3api-25a52e9ecd15">#25 xib練習＆串接第三方天氣API</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[#24 使用 MKLocalSearch 搜尋附近商家打卡]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/24-%E4%BD%BF%E7%94%A8-mklocalsearch-%E6%90%9C%E5%B0%8B%E9%99%84%E8%BF%91%E5%95%86%E5%AE%B6%E6%89%93%E5%8D%A1-c180f06442f9?source=rss-d1d3fbf1cc26------2</link>
            <guid isPermaLink="false">https://medium.com/p/c180f06442f9</guid>
            <dc:creator><![CDATA[Adam]]></dc:creator>
            <pubDate>Sun, 20 Oct 2024 15:55:28 GMT</pubDate>
            <atom:updated>2024-10-21T08:38:39.608Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>MKLocalSearch</strong> 搜尋<br><strong>MKLocalSearchCompleter </strong>顯示相關的清單<br><strong>sheetPresentationController </strong>顯示部分高度的sheet畫面<br><strong>Core Data </strong>儲存資料</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NM1goe5Ji8sgo45e_GBDbQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H1FQr8xGW1bsiJQ0nu4Jlw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tg9zso1aHDkGJGpva4IfEw.png" /></figure><blockquote><strong>DEMO:</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*p0MNRyp7F3V1I1zb7tY_Qw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*pclec9wzv-A5tv54WTNo6A.gif" /></figure><ul><li><strong><em>顯示使用者位置在地圖上</em></strong></li></ul><p>先在畫面上放上元件 Map Kit View , Search Bar。</p><p>宣告 locationManager = CLLocationManager()，並設置 delegate，要記得去 Info 加上請求權限的文字。在 didUpdateLocations 方法裡將使用者位置顯示在地圖上。</p><p>在放上一個 Button 拉 IBAction ( goToCurrentLocation )，點擊按鈕讓地圖可以返回使用者位置。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YhBPFXitXh4c10LWURaEBQ.png" /></figure><pre>import UIKit<br>import MapKit<br>import CoreLocation<br><br>class MapViewController: UIViewController {<br><br>    @IBOutlet weak var mapView: MKMapView!<br>    @IBOutlet weak var searchBar: UISearchBar!<br><br>    // CLLocationManager 用於獲取用戶的當前位置<br>    let locationManager = CLLocationManager()<br>    <br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        <br>        locationManager.delegate = self<br>        locationManager.requestWhenInUseAuthorization()// 請求應用時允許使用位置的權限<br>        locationManager.startUpdatingLocation() // 獲取用戶當前的位置<br>        mapView.showsUserLocation = true // 顯示用戶當前位置在地圖上<br>    }<br><br>    // 點擊按鈕移動到當前位置<br>    @IBAction func goToCurrentLocation(_ sender: Any) {<br>        guard let userLocation = locationManager.location else { return }<br>        setLocation(userLocation.coordinate)<br>    }<br>    <br>    // 設定地圖的顯示<br>    func setLocation(_ coordinate: CLLocationCoordinate2D) {<br>        let regionRadius: CLLocationDistance = 1000.0 //顯示半徑（以米為單位）<br>        let coordinateRegion = MKCoordinateRegion(center: coordinate, latitudinalMeters: regionRadius, longitudinalMeters: regionRadius)<br>        mapView.setRegion(coordinateRegion, animated: true)<br>    }<br><br>}<br><br>// CLLocationManagerDelegate 用於處理位置更新<br>extension MapViewController: CLLocationManagerDelegate {<br>    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {<br>        guard let userLocation = locations.first else { return }<br>        setLocation(userLocation.coordinate)<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*hsAncQQVdrkrpvV8r2sxOA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*dfBAD4oVUnQV3beV46D5LQ.gif" /></figure><ul><li><strong><em>使用 MKLocalSearch 搜尋</em></strong></li></ul><p>設置 searchBar 的 delegate ，在 searchBarSearchButtonClicked 方法裡判斷searchBar 文字不是空值時，執行 searchLocation 方法搜尋。</p><pre>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        <br>        searchBar.delegate = self<br>    }<br><br>    // 使用搜尋功能來顯示地點，限定範圍為當前地圖顯示區域<br>    func searchLocation(query: String) {<br>        let request = MKLocalSearch.Request()<br>        request.naturalLanguageQuery = query<br>        <br>        // 限制搜尋範圍為當前地圖顯示的區域<br>        let mapRegion = mapView.region<br>        request.region = MKCoordinateRegion(center: mapRegion.center, span: mapRegion.span)<br>        <br>        let search = MKLocalSearch(request: request)<br>        search.start { [weak self] response, error in<br>            guard let self = self, let response = response else {<br>                print(&quot;搜尋失敗: \(String(describing: error?.localizedDescription))&quot;)<br>                return<br>            }<br>            <br>            // 移除所有的地圖標註<br>            self.mapView.removeAnnotations(self.mapView.annotations)<br>            <br>            // 將所有搜尋結果的地點顯示在地圖上<br>            for mapItem in response.mapItems {<br>                let coordinate = mapItem.placemark.coordinate<br>                let annotation = MKPointAnnotation()<br>                annotation.coordinate = coordinate<br>                annotation.title = mapItem.name<br>                annotation.subtitle = mapItem.placemark.title<br>                self.mapView.addAnnotation(annotation)<br>            }<br>        }<br>    }<br><br>    extension MapViewController: UISearchBarDelegate {<br>        func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {<br>            if let query = searchBar.text, !query.isEmpty {<br>                searchLocation(query: query)<br>            }<br>            searchBar.resignFirstResponder() // 收起鍵盤<br>        }<br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*6ob4oCLlHDQuc1aiM_LEZg.gif" /></figure><ul><li><strong><em>使用 MKLocalSearchCompleter，輸入搜尋文字時會顯示相關的清單</em></strong></li></ul><p>設定 SearchCompleter 的 delegate，在 extension 裡將搜尋建議的資料存入 searchResults 。</p><p>UISearchBarDelegate 裡要再加上一個方法 textDidChange ，當搜尋文字改變時將文字傳遞給 searchCompleter ，重新生成建議。</p><p>用程式生成一個 TableView 加在 searchBar 下面，用來顯示自動提供的搜尋建議。方法 didSelectRowAt 設定被點選時，執行 searchLocation 。</p><pre><br>    let searchCompleter = MKLocalSearchCompleter()  // 自動提供搜尋建議<br>    var searchResults = [MKLocalSearchCompletion]() // 用來儲存搜尋建議<br>    var searchCompleterTableView: UITableView! //用來顯示搜尋建議的TableView<br>    <br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        <br>        // 初始化 tableView 用於顯示搜尋建議<br>        searchCompleterTableView = UITableView()<br>        searchCompleterTableView.delegate = self<br>        searchCompleterTableView.dataSource = self<br>        searchCompleterTableView.isHidden = true // 預設隱藏<br>        view.addSubview(searchCompleterTableView)<br>        <br>        // 設定 searchCompleter 的 delegate<br>        searchCompleter.delegate = self<br>        searchCompleter.region = mapView.region // 初始時設定搜尋範圍為當前地圖範圍<br>    }<br><br>    //把搜尋建議的 tableView 加在 searchBar 下面<br>    override func viewDidLayoutSubviews() {<br>        super.viewDidLayoutSubviews()<br>        searchCompleterTableView.frame = CGRect(x: 0, y: searchBar.frame.maxY, width: view.bounds.width, height: 300)<br>    }<br><br>// UISearchBarDelegate<br>extension MapViewController: UISearchBarDelegate {<br>    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {<br>        // 當搜尋文字改變時，將文字傳遞給 searchCompleter 來獲取自動完成建議<br>        searchCompleter.queryFragment = searchText<br>    }<br>    <br>    func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {<br>        if let query = searchBar.text, !query.isEmpty {<br>            searchLocation(query)<br>        }<br>        searchBar.resignFirstResponder() // 收起鍵盤<br>    }<br>}<br><br>// MKLocalSearchCompleterDelegate<br>extension MapViewController: MKLocalSearchCompleterDelegate {<br>    func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {<br>        // 當自動完成建議更新時，將結果存入 searchResults 並重新載入 TableView<br>        searchResults = completer.results<br>        searchCompleterTableView.reloadData()<br>        searchCompleterTableView.isHidden = searchResults.isEmpty<br>    }<br>}<br><br>// UITableViewDelegate<br>extension MapViewController: UITableViewDelegate, UITableViewDataSource {<br>    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {<br>        searchResults.count<br>    }<br>    <br>    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {<br>        let cell = tableView.dequeueReusableCell(withIdentifier: &quot;cell&quot;) ?? UITableViewCell(style: .subtitle, reuseIdentifier: &quot;cell&quot;)<br>        let searchResult = searchResults[indexPath.row]<br>        cell.textLabel?.text = searchResult.title<br>        cell.detailTextLabel?.text = searchResult.subtitle<br>        return cell<br>    }<br>    <br>    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {<br>        // 當使用者點擊某個建議時，使用建議的完整文字進行搜尋<br>        let selectedSuggestion = searchResults[indexPath.row]<br>        searchLocation(selectedSuggestion.title)<br>        searchBar.text = selectedSuggestion.title<br>        searchCompleterTableView.isHidden = true // 隱藏建議列表<br>        searchBar.resignFirstResponder() // 收起鍵盤<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*ortXuZQ7dsc48FBEbA7olw.gif" /></figure><ul><li><strong><em>顯示搜尋清單，點選後地圖跟著移動</em></strong></li></ul><p>在 Storyboard 新增一個 PlaceTableViewController 用來顯示搜尋出來的地點，因為顯示的方式要由下而上出現，所以拉segue時要選 Present Modally ，然後用 <strong>IBSegueAction </strong>把資料傳過去顯示。</p><p>在 <strong>IBSegueAction </strong>裡用 sheetPresentationController 可以讓顯示的搜尋清單只顯示一半。</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/ios-15-%E7%8C%B6%E6%8A%B1%E7%90%B5%E7%90%B6%E5%8D%8A%E9%81%AE%E9%9D%A2-%E9%A1%AF%E7%A4%BA%E4%B8%80%E5%8D%8A%E7%9A%84-sheet-%E7%95%AB%E9%9D%A2-b13448a76cb0">只顯示部分高度的 sheet 畫面</a></p><p>點選清單上的地點，利用 delegate 把資料傳到前一頁讓地圖移動。</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/%E5%88%A9%E7%94%A8-delegate-%E8%AE%93%E4%B8%8D%E5%90%8C%E5%85%83%E4%BB%B6%E6%BA%9D%E9%80%9A-%E4%BB%A5%E8%B3%87%E6%96%99%E5%9B%9E%E5%82%B3%E5%88%B0%E5%89%8D%E4%B8%80%E9%A0%81-controller-%E7%82%BA%E4%BE%8B-ba215f3d2596">利用 delegate 讓不同元件溝通，以資料回傳到前一頁 controller 為例</a></p><pre>var mapItems = [MKMapItem]()<br><br>func searchLocation(_ query: String) {<br>        ...<br>        ...<br>        self.mapItems = response.mapItems<br>        self.dismiss(animated: true)<br>        self.performSegue(withIdentifier: &quot;showPlaceSheet&quot;, sender: nil)<br>}<br>    <br>// 傳資料<br>@IBSegueAction func showPlaceSheet(_ coder: NSCoder) -&gt; PlaceTableViewController? {<br>    let controller = PlaceTableViewController(coder: coder)<br>    controller?.delegate = self<br>    controller?.mapItems = mapItems<br>        <br>    if let sheetPresentationController = controller?.sheetPresentationController {<br>        sheetPresentationController.prefersGrabberVisible = true<br>        sheetPresentationController.prefersScrollingExpandsWhenScrolledToEdge = false<br>        sheetPresentationController.largestUndimmedDetentIdentifier = .medium<br>        sheetPresentationController.detents = [<br>            .medium(),<br>            .large(),<br>            .custom(resolver: { context in<br>                context.maximumDetentValue * 0.4<br>            })<br>        ]<br>    }<br>        <br>    return controller<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*vFDI2ii1DwmQVFMl1V9Muw.gif" /></figure><ul><li><strong><em>修改地圖顯示的圖標</em></strong></li></ul><p>MKMapItem 有一個 pointOfInterestCategory 屬性，可以用來識別這個地點的類別，例如餐廳、景點、加油站等。</p><p>系統內建顯示的圖標 MKMarkerAnnotationView 預設是紅色的圖釘，可以自定義一個 MKAnnotation ，加一個參數 category 來儲存 MKMapItem 的 pointOfInterestCategory 屬性，在根據這參數顯示不同圖案。</p><pre>class CustomAnnotation: NSObject, MKAnnotation {<br>    var coordinate: CLLocationCoordinate2D<br>    var title: String?<br>    var subtitle: String?<br>    <br>    // 自訂屬性<br>    var category: String?<br>    <br>    init(coordinate: CLLocationCoordinate2D, title: String?, subtitle: String?, category: String?) {<br>        self.coordinate = coordinate<br>        self.title = title<br>        self.subtitle = subtitle<br>        self.category = category<br>    }<br>}<br><br>extension MapViewController: MKMapViewDelegate {<br>    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -&gt; MKAnnotationView? {<br>        if annotation is MKUserLocation { return nil }<br>        <br>        guard let customAnnotation = annotation as? CustomAnnotation else { return nil }<br>        <br>        let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: &quot;pin&quot;)<br>        annotationView.markerTintColor = .orange<br>                <br>        //根據 category 更換顯示的圖片<br>        switch customAnnotation.category {<br>        case &quot;MKPOICategoryRestaurant&quot;:<br>            annotationView.glyphImage = UIImage(systemName: &quot;fork.knife&quot;)<br>        case &quot;MKPOICategoryCafe&quot;:<br>            annotationView.glyphImage = UIImage(systemName: &quot;cup.and.heat.waves.fill&quot;)<br>        case &quot;MKPOICategoryFoodMarket&quot;:<br>            annotationView.glyphImage = UIImage(systemName: &quot;storefront&quot;)<br>        case &quot;MKPOICategoryHotel&quot;:<br>            annotationView.glyphImage = UIImage(systemName: &quot;bed.double.fill&quot;)<br>        case &quot;MKPOICategoryGasStation&quot;:<br>            annotationView.glyphImage = UIImage(systemName: &quot;fuelpump.fill&quot;)<br>        case &quot;MKPOICategoryNightlife&quot;:<br>            annotationView.glyphImage = UIImage(systemName: &quot;wineglass.fill&quot;)<br>        default:<br>            break<br>        }<br>        <br>        return annotationView<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*xHMDB7ySOk1LVeLEDCUrQg.gif" /></figure><ul><li><strong><em>顯示使用者到地點的路徑</em></strong></li></ul><p>設置兩個 MKMapItem 起點和終點，利用 MKDirections 計算路徑，MKPolyline繪製路線時會自動調用 mapView(_:rendererFor:)，可以在這裡自定義線條的顏色和樣式。</p><pre>    // 當前選擇的圖標<br>    var selectedAnnotation: MKAnnotation?<br><br>    // 繪製路線<br>    @IBAction func drawRoute(_ sender: Any) {<br>        guard let userLocation = locationManager.location else { return }<br>        guard selectedAnnotation != nil else { return }<br>        dismiss(animated: true)<br>        <br>        // 設置起點和終點<br>        let sourcePlacemark = MKPlacemark(coordinate: userLocation.coordinate)<br>        let destinationPlacemark = MKPlacemark(coordinate: selectedAnnotation!.coordinate)<br>        <br>        let sourceMapItem = MKMapItem(placemark: sourcePlacemark)<br>        let destinationMapItem = MKMapItem(placemark: destinationPlacemark)<br>        <br>        // 計算路線<br>        calculateRoute(from: sourceMapItem, to: destinationMapItem)<br>    }<br><br>    // 計算路線<br>    func calculateRoute(from source: MKMapItem, to destination: MKMapItem) {<br>        let directionsRequest = MKDirections.Request()<br>        directionsRequest.source = source<br>        directionsRequest.destination = destination<br>        directionsRequest.transportType = .automobile // 可以是 .walking, .transit 等<br>        <br>        let directions = MKDirections(request: directionsRequest)<br>        directions.calculate { response, error in<br>            guard let response = response else {<br>                print(&quot;Error calculating directions: \(error?.localizedDescription ?? &quot;Unknown error&quot;)&quot;)<br>                return<br>            }<br>            <br>            self.mapView.removeOverlays(self.mapView.overlays)<br>            <br>            // 繪製路線<br>            for route in response.routes {<br>                self.mapView.addOverlay(route.polyline)<br>            }<br>        }<br>    }<br><br>extension MapViewController: MKMapViewDelegate {<br>    func mapView(_ mapView: MKMapView, rendererFor overlay: any MKOverlay) -&gt; MKOverlayRenderer {<br>        if let polyline = overlay as? MKPolyline {<br>            let renderer = MKPolylineRenderer(polyline: polyline)<br>            renderer.strokeColor = UIColor.link // 路徑顏色<br>            renderer.lineWidth = 4.0 // 路徑寬度<br>            return renderer<br>        }<br>        return MKOverlayRenderer()<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*abRZPV5nzI_o3wZGI3zPBQ.gif" /></figure><ul><li><strong><em>Core Data 新增 ＆ 讀取 打卡紀錄</em></strong></li></ul><p>創建一個 Record 的Entity，新增4個 Attribute，分別用來存地點、地址、日期和打卡內容。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_nnZAM_YyfBGQmAS40qgZg.png" /></figure><p>在 AppDelegate 加入 container 的擴充方法。</p><p>在 SceneDelegate 將 persistentContainer 傳給需要使用的 controller，這樣之後就可以在 controller 裡直接使用 container 來進行 Core Data 的 CRUD。</p><pre>/************ AppDelegate ************************/<br>extension NSPersistentContainer {<br>    func saveContext () {<br>        if viewContext.hasChanges {<br>            do {<br>                try viewContext.save()<br>            } catch {<br>                // Replace this implementation with code to handle the error appropriately.<br>                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.<br>                let nserror = error as NSError<br>                fatalError(&quot;Unresolved error \(nserror), \(nserror.userInfo)&quot;)<br>            }<br>        }<br>    }<br>}<br><br>/************ SceneDelegate ************************/<br>    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {<br>        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.<br>        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.<br>        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).<br>        guard let _ = (scene as? UIWindowScene) else { return }<br>        <br>        //設定 MapViewController ＆ RecordViewController 的 container<br>        if let tabController = window?.rootViewController as? UITabBarController {<br>            let appDelegate = UIApplication.shared.delegate as? AppDelegate<br>            <br>            let mapViewController = tabController.viewControllers?.first as? MapViewController<br>            mapViewController?.container = appDelegate?.persistentContainer<br>            <br>            let recordViewController = tabController.viewControllers?.last as? RecordViewController<br>            recordViewController?.container = appDelegate?.persistentContainer<br>            <br>        }<br>    }</pre><p>點擊打卡按鈕，用 UIAlertController 彈出視窗打卡。</p><p>建立保存資料和讀取資料的方法，讀取資料的方法加了一個參數，用NSPredicate 來搜尋地點。</p><pre>// 定義一個 NSPersistentContainer 變數來管理 Core Data 容器<br>var container: NSPersistentContainer!<br><br>// 定義一個存放 Record 物件的陣列<br>var records = [Record]()<br><br>// Core Data保存資料<br>func save(place: String, address: String, content: String) {<br>    let context = container.viewContext<br>    <br>    // 創建一個新的 Record 實體，並將其與上下文關聯<br>    let record = Record(context: context)<br>    record.place = place         // 設置地點<br>    record.address = address     // 設置地址<br>    record.date = Date()         // 設置當前日期和時間<br>    record.content = content     // 設置內容<br>    <br>    // 保存<br>    container.saveContext()<br>}<br><br>// Core Data讀取資料<br>func getRecordDate(_ text: String? = nil) {<br>    // 創建一個 Core Data 的取回請求 (fetch request) 來取回 Record 實體<br>    let request = Record.fetchRequest()<br>    <br>    // 如果 text 參數有值，則設置篩選條件<br>    if let text {<br>        // 設置篩選條件為地點包含指定的文本（不區分大小寫）<br>        request.predicate = NSPredicate(format: &quot;place CONTAINS[c] %@&quot;, text)<br>    }<br>    <br>    // 設置排序條件，根據日期 (date) 屬性進行降序排列<br>    request.sortDescriptors = [<br>        NSSortDescriptor(keyPath: \Record.date, ascending: false)<br>    ]<br>    <br>    let context = container.viewContext<br>    do {<br>        // 執行取回請求，將結果保存到 records 陣列<br>        records = try context.fetch(request)<br>    } catch {<br>        // 如果發生錯誤，打印錯誤信息<br>        print(&quot;Error fetching records: \(error)&quot;)<br>    }<br>    <br>    // 重新載入表格視圖，顯示最新的數據<br>    recordTableView.reloadData()<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*TGUxrlbdOGrhnxpK1zZvcA.gif" /></figure><ul><li><strong><em>Core Data 更新 ＆ 刪除 打卡紀錄</em></strong></li></ul><p>用 tableView(_:trailingSwipeActionsConfigurationForRowAt) 建立編輯和刪除兩個 UIContextualAction。</p><p><a href="https://anny86023.medium.com/uitableview-swipe-action-%E5%AE%A2%E8%A3%BD%E5%8C%96%E6%BB%91%E5%8B%95%E6%8C%89%E9%88%95%E5%8B%95%E4%BD%9C-7b9e90155815">UITableView Swipe Action — 客製化滑動按鈕動作</a></p><p>在編輯和刪除兩個UIContextualAction裡，進行 Core Data 的更新和刪除。</p><pre>@IBOutlet weak var recordTableView: UITableView!<br>@IBOutlet weak var searchTextField: UITextField!<br>    <br>var container: NSPersistentContainer!<br>var records = [Record]()<br><br>extension RecordViewController: UITableViewDataSource, UITableViewDelegate {<br><br>    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -&gt; UISwipeActionsConfiguration? {<br>        let record = self.records[indexPath.row]<br>        //刪除的滑動按鈕<br>        let deleteAction = UIContextualAction(style: .normal, title: &quot;刪除&quot;) { (action, view, completionHandler) in<br>            // Core Data 刪除資料<br>            let context = self.container.viewContext<br>            context.delete(record)<br>            self.container.saveContext()<br>            self.records.remove(at: indexPath.row)<br>            tableView.reloadData()<br>            <br>            completionHandler(true)<br>        }<br>        // 按鈕背景顏色<br>        deleteAction.backgroundColor = .systemRed<br>        <br>        //編輯的滑動按鈕<br>        let editedAction = UIContextualAction(style: .normal, title: &quot;編輯&quot;) { (action, view, completionHandler) in<br>            <br>            let alertController = UIAlertController(title: record.place, message: record.address, preferredStyle: .alert)<br>            let okAction = UIAlertAction(title: &quot;OK&quot;, style: .default) { _ in<br>                let content = alertController.textFields?.first?.text<br>                guard let content else { return }<br>                guard content != &quot;&quot; else { return }<br>                record.content = content<br>                self.updateRecord(record)// 更新打卡紀錄<br>                tableView.reloadData()<br>            }<br>            alertController.addAction(okAction)<br>            let cancelAction = UIAlertAction(title: &quot;Cancel&quot;, style: .cancel)<br>            alertController.addAction(cancelAction)<br>            alertController.addTextField { textField in<br>                textField.text = record.content<br>            }<br>            self.present(alertController, animated: true, completion: nil)<br>            <br>            completionHandler(true)<br>        }<br>        // 按鈕背景顏色<br>        editedAction.backgroundColor = .systemOrange<br>        <br>        let prevention = UISwipeActionsConfiguration(actions: [deleteAction, editedAction])<br>        prevention.performsFirstActionWithFullSwipe = false<br>        <br>        return prevention<br>    }<br>}<br><br>// 更新打卡紀錄<br>func updateRecord(_ record: Record) {<br>    // Core Data 更新資料<br>    let context = self.container.viewContext<br>    let objectID = record.objectID<br>    do {<br>        let object = try context.existingObject(with: objectID)<br>        object.setValue(record.content, forKey: &quot;content&quot;)<br>        self.container.saveContext()<br>    } catch {<br>        print(error)<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*Uzuwkm57lisqB1IqlNTOug.gif" /></figure><blockquote><strong>Github:</strong></blockquote><p><a href="https://github.com/ggisfun/MyMapKit.git">GitHub - ggisfun/MyMapKit</a></p><blockquote><strong>Reference:</strong></blockquote><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/169-%E4%BD%BF%E7%94%A8-mklocalsearch-%E6%88%96-google-place-api-%E6%90%9C%E5%B0%8B%E9%99%84%E8%BF%91%E5%95%86%E5%AE%B6%E6%89%93%E5%8D%A1-6d01aaaa914a">#169 使用 MKLocalSearch 或 Google Place API 搜尋附近商家打卡</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c180f06442f9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/24-%E4%BD%BF%E7%94%A8-mklocalsearch-%E6%90%9C%E5%B0%8B%E9%99%84%E8%BF%91%E5%95%86%E5%AE%B6%E6%89%93%E5%8D%A1-c180f06442f9">#24 使用 MKLocalSearch 搜尋附近商家打卡</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[#23 照片編輯 App]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/23-%E7%85%A7%E7%89%87%E7%B7%A8%E8%BC%AF-app-425eab150d99?source=rss-d1d3fbf1cc26------2</link>
            <guid isPermaLink="false">https://medium.com/p/425eab150d99</guid>
            <dc:creator><![CDATA[Adam]]></dc:creator>
            <pubDate>Sun, 13 Oct 2024 03:00:58 GMT</pubDate>
            <atom:updated>2024-10-13T11:49:39.484Z</atom:updated>
            <content:encoded><![CDATA[<p>作業練習實作照片編輯的一些功能～</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*liKFJRoIMLRtGFQ4dcHz5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kHJ-mZCnJfzeRJEm5CbqRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kIQ7KBcGfsXqAaYHgMhpiQ.png" /></figure><blockquote><strong>DEMO:</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*3JUpNlyq07LzN3Idn3KV1g.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*Y4KBDBzwEtFiubOsY0_GRA.gif" /></figure><p>上面的按鈕功能是鏡像翻轉、旋轉、重置、加入文字、文字顏色和存檔，圖片則是加入縮放手勢，可以放大縮小，最下面就是調整、濾鏡、裁切三個主要功能。</p><p>因為大部分的功能都是參考之前學長姐的文章，附上連結～</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%E6%95%99%E5%AE%A4/task-11-%E7%85%A7%E7%89%87%E7%B7%A8%E8%BC%AFapp-photoeditor-03-%E7%85%A7%E7%89%87%E8%AA%BF%E8%89%B2-%E6%BF%BE%E9%8F%A1-13b951211d2b">#Task-11 照片編輯App- PhotoEditor (03- 照片調色＆濾鏡)</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/swift-hw-7-%E7%85%A7%E7%89%87%E7%B7%A8%E8%BC%AFapp-45dead9ea908">#7.：照片編輯APP</a></li></ul><blockquote><strong>裁切</strong></blockquote><p>在拖曳裁切範圍時要顯示裁切框的網格線，所以自訂一個裁切框類別CropOverlayView。</p><pre>import UIKit<br><br>class CropOverlayView: UIView {<br>    <br>    override func draw(_ rect: CGRect) {<br>        let path = UIBezierPath()<br>        let numberOfLines = 2 // 每個方向的網格線數量<br>        <br>        // 繪製垂直線<br>        for i in 1...numberOfLines {<br>            let x = rect.width / CGFloat(numberOfLines + 1) * CGFloat(i)<br>            path.move(to: CGPoint(x: x, y: 0))<br>            path.addLine(to: CGPoint(x: x, y: rect.height))<br>        }<br>        <br>        // 繪製水平線<br>        for i in 1...numberOfLines {<br>            let y = rect.height / CGFloat(numberOfLines + 1) * CGFloat(i)<br>            path.move(to: CGPoint(x: 0, y: y))<br>            path.addLine(to: CGPoint(x: rect.width, y: y))<br>        }<br>        <br>        UIColor.white.setStroke() // 網格線的顏色<br>        path.lineWidth = 1<br>        path.stroke()<br>    }<br>}</pre><p>裁切的功能，主要是透過 touchesBegan / touchesMoved / touchesEnded 這三個方法來確認要裁切的範圍，在用 .cropping(to: rect) 來裁切圖片。</p><p>要在 touchesMoved 方法裡要用cropOverlayView.setNeedsDisplay() 重新繪製網格，這樣在選取範圍時才會顯示裁切框的網格線。</p><pre><br>    var startPoint: CGPoint?<br><br>    let cropOverlayView = CropOverlayView()// 使用自訂義的裁切框<br><br>    override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {<br>        guard currentMode == .crop else { return }<br>        guard let touch = touches.first else { return }<br>        let point = touch.location(in: imageView)<br>        <br>        // 確保觸控點在 imageView 內<br>        if imageView.bounds.contains(point) {<br>            startPoint = point<br>            cropOverlayView.frame = CGRect(x: point.x, y: point.y, width: 0, height: 0)<br>            cropOverlayView.layer.borderWidth = 1<br>            cropOverlayView.layer.borderColor = UIColor.white.cgColor<br>            cropOverlayView.backgroundColor = UIColor.black.withAlphaComponent(0.5)  // 背景設為透明，僅顯示網格<br>            imageView.addSubview(cropOverlayView)<br>        }<br>    }<br><br>    override func touchesMoved(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {<br>        guard let startPoint = startPoint, let touch = touches.first else { return }<br>        let currentPoint = touch.location(in: imageView)<br>        <br>        let width = currentPoint.x - startPoint.x<br>        let height = currentPoint.y - startPoint.y<br>        <br>        // 更新裁切區域和網格顯示<br>        cropOverlayView.frame = CGRect(x: startPoint.x, y: startPoint.y, width: width, height: height)<br>        cropOverlayView.setNeedsDisplay()  // 重新繪製網格<br>    }<br><br>    override func touchesEnded(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {<br>        guard let startPoint = startPoint, let touch = touches.first else { return }<br>        let endPoint = touch.location(in: imageView)<br>        <br>        // 確定最終的裁剪矩形<br>        let cropRect = CGRect(x: min(startPoint.x, endPoint.x),<br>                              y: min(startPoint.y, endPoint.y),<br>                              width: abs(endPoint.x - startPoint.x),<br>                              height: abs(endPoint.y - startPoint.y))<br>        <br>        // 更新圖片<br>        if let croppedImage = cropImage(to: cropRect, imageView: imageView) {<br>            imageView.image = croppedImage<br>        }<br>        <br>        // 清理和重置狀態<br>        cropOverlayView.removeFromSuperview()<br>        self.startPoint = nil<br>    }<br><br>    // 裁剪圖片的輔助函數<br>    func cropImage(to rect: CGRect, imageView: UIImageView) -&gt; UIImage? {<br>        guard let image = imageView.image else { return nil }<br>        <br>        // 計算 imageView 的實際顯示範圍<br>        let imageSize = image.size<br>        let imageViewSize = imageView.bounds.size<br>        let scaleX = imageSize.width / imageViewSize.width<br>        let scaleY = imageSize.height / imageViewSize.height<br>        <br>        // 將 cropRect 從 imageView 的坐標轉換為圖片的實際像素坐標<br>        let scaledCropRect = CGRect(x: rect.origin.x * scaleX,<br>                                    y: rect.origin.y * scaleY,<br>                                    width: rect.width * scaleX,<br>                                    height: rect.height * scaleY)<br>        <br>        // 裁剪圖片<br>        if let cgImage = image.cgImage?.cropping(to: scaledCropRect) {<br>            return UIImage(cgImage: cgImage)<br>        }<br>        <br>        return nil<br>    }</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2XYcx5FKI70%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2XYcx5FKI70&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2XYcx5FKI70%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/43d24a544da550ff7cf04dff7db7f6e8/href">https://medium.com/media/43d24a544da550ff7cf04dff7db7f6e8/href</a></iframe><p>調整圖片比例，加入5個按鈕設置tag值0~4</p><pre>    <br>    var currentImage: UIImage? //當前顯示的圖片<br><br>    @IBAction func changeViewScale(_ sender: UIButton) {<br>        guard let image = currentImage else { return }<br>        <br>        var cropRect = CGRect.zero<br>        <br>        switch sender.tag {<br>        case 0:<br>            // 原圖裁剪，保持不變<br>            cropRect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)<br>        case 1:<br>            // 正方形裁剪<br>            let sideLength = min(image.size.width, image.size.height)<br>            cropRect = CGRect(x: (image.size.width - sideLength) / 2, y: (image.size.height - sideLength) / 2, width: sideLength, height: sideLength)<br>        case 2:<br>            // 9:16 比例裁剪<br>            let height = image.size.height<br>            let width = min(height * (9.0 / 16.0), image.size.width)  // 確保不超出範圍<br>            cropRect = CGRect(x: (image.size.width - width) / 2, y: 0, width: width, height: height)<br>        case 3:<br>            // 4:5 比例裁剪<br>            let height = image.size.height<br>            let width = min(height * (4.0 / 5.0), image.size.width)  // 確保不超出範圍<br>            cropRect = CGRect(x: (image.size.width - width) / 2, y: 0, width: width, height: height)<br>        case 4:<br>            // 3:4 比例裁剪<br>            let height = image.size.height<br>            let width = min(height * (3.0 / 4.0), image.size.width)  // 確保不超出範圍<br>            cropRect = CGRect(x: (image.size.width - width) / 2, y: 0, width: width, height: height)<br>        default:<br>            return<br>        }<br>        <br>        // 裁切圖片<br>        if let croppedImage = cropImage(to: cropRect, image: image) {<br>            imageView.image = croppedImage<br>        }<br>    }<br>    <br>    // 裁切圖片的func<br>    func cropImage(to rect: CGRect, image: UIImage) -&gt; UIImage? {<br>        guard let cgImage = image.cgImage else { return nil }<br>        if let croppedCgImage = cgImage.cropping(to: rect) {<br>            return UIImage(cgImage: croppedCgImage)<br>        }<br>        return nil<br>    }</pre><p>這次作業裁切的功能花了很多時間，也看了很多學長姐的文章，後來發現其實有很方便的第三方套件，TOCropViewController 畫面精美又好用，早知道就直接用了～～</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D9wGCI45UQN_O4mZ2FG3YQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*bmMv522ejOzYFNyM80Qf4w.gif" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXPcuAg0Xctw%3Fstart%3D132%26feature%3Doembed%26start%3D132&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXPcuAg0Xctw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FXPcuAg0Xctw%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/5be5a13d627a8e7b859d0ed382c65004/href">https://medium.com/media/5be5a13d627a8e7b859d0ed382c65004/href</a></iframe><blockquote><strong>Github:</strong></blockquote><p><a href="https://github.com/ggisfun/MyPhotoEdit.git">GitHub - ggisfun/MyPhotoEdit</a></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%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/95-%E7%85%A7%E7%89%87%E7%B7%A8%E8%BC%AF-app-335ef37cc707">#95 照片編輯 App</a></li><li><a href="https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CoreImageFilterReference/?source=post_page-----4ff3864ad57a--------------------------------#//apple_ref/doc/filter/ci/CIGammaAdjust">Core Image Filter Reference</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/ciimage-%E8%AE%8A-uiimage-%E7%9A%84%E8%BD%89%E5%90%91%E5%95%8F%E9%A1%8C-9e0322a451f1">CIImage 變 UIImage 的轉向問題</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/83-%E5%88%A9%E7%94%A8-cgaffinetransform-%E7%B8%AE%E6%94%BE-%E4%BD%8D%E7%A7%BB%E5%92%8C%E6%97%8B%E8%BD%89-e061df9ed672">利用 CGAffineTransform 縮放，位移，旋轉和鏡像翻轉</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=425eab150d99" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/23-%E7%85%A7%E7%89%87%E7%B7%A8%E8%BC%AF-app-425eab150d99">#23 照片編輯 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>
        <item>
            <title><![CDATA[#22 UIPickerView 練習_汽車選擇]]></title>
            <link>https://medium.com/peter-pan-swift-ios-class/22-uipickerview-%E7%B7%B4%E7%BF%92-%E6%B1%BD%E8%BB%8A%E9%81%B8%E6%93%87-751679756e98?source=rss-d1d3fbf1cc26------2</link>
            <guid isPermaLink="false">https://medium.com/p/751679756e98</guid>
            <dc:creator><![CDATA[Adam]]></dc:creator>
            <pubDate>Fri, 04 Oct 2024 09:03:49 GMT</pubDate>
            <atom:updated>2024-10-04T12:23:20.393Z</atom:updated>
            <content:encoded><![CDATA[<p>作業練習使用PickerView</p><blockquote><strong>DEMO:</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zs3KsHm9WQSh7Tjex7WtXw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*SxYqWyjkhjG47XiR3MswlQ.gif" /><figcaption>圖片來源：<a href="https://c.8891.com.tw/Models">https://c.8891.com.tw/Models</a></figcaption></figure><p>要讓PickerView像鍵盤一樣從下往上出現，要先加入一個TextField並隱藏起來，在讓PickerView和Toolbar各別取代TextField的inputView 和inputAccessoryView。</p><p>Toolbar上面呈現圓角，可以用屬性maskedCorners來設定部分圓角。</p><pre>    @IBOutlet weak var carTextField: UITextField!<br>    @IBOutlet var carPickerView: UIPickerView!<br>    @IBOutlet var carToolbar: UIToolbar!<br>       <br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        // Do any additional setup after loading the view.<br>        <br>        carTextField.isHidden = true<br>        carTextField.inputView = carPickerView<br>        carTextField.inputAccessoryView = carToolbar  <br><br>        carToolbar.layer.cornerRadius = 10<br>        carToolbar.clipsToBounds = true<br>        //指定上半部呈現圓角<br>        carToolbar.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]     <br>    }</pre><p>加入Label 和 ImageView，然後Label要設定 .isUserInteractionEnabled = true還要加上tap gesture recognizer，這樣Label才可以點選，拉 IBAction。</p><p>Toolbar 加入 Cancel &amp; Done 的 Bar Button Item，拉 IBAction。</p><pre>    @IBOutlet weak var carLabel: UILabel!<br>    @IBOutlet weak var carImageView: UIImageView!<br><br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        <br>        //開啟Label交互作用<br>        carLabel.isUserInteractionEnabled = true<br>    }<br><br>    //tap gesture recognizer<br>    @IBAction func selectCar(_ sender: Any) {<br>        carTextField.becomeFirstResponder()<br>    }<br>    <br>    //Bar Button Item =&gt; Cancel<br>    @IBAction func selectCarCancel(_ sender: Any) {<br>        view.endEditing(true)<br>    }<br>    <br>    //Bar Button Item =&gt; Done<br>    @IBAction func selectCarDone(_ sender: Any) {<br>        let selectedBrand = carPickerView.selectedRow(inComponent: 0)<br>        let selectedModel = carPickerView.selectedRow(inComponent: 1)<br>        carLabel.text = cars[selectedBrand].brand + &quot; &quot; + cars[selectedBrand].model[selectedModel]<br>        carImageView.image = UIImage(named: cars[selectedBrand].model[selectedModel])<br>        view.endEditing(true)<br>    }</pre><p>設定要顯示的車子資料</p><pre>struct Car {<br>    let brand: String<br>    let model: [String]<br>}<br><br>let cars = [<br>    Car(brand: &quot;Toyota&quot;, model: [&quot;Corolla Altis&quot;, &quot;Camry&quot;, &quot;Corolla Cross&quot;, &quot;RAV4&quot;, &quot;Yaris Cross&quot;]),<br>    Car(brand: &quot;Honda&quot;, model: [&quot;Civic&quot;, &quot;Fit&quot;, &quot;HR-V&quot;, &quot;CR-V&quot;]),<br>    Car(brand: &quot;Nissan&quot;, model: [&quot;Altima&quot;, &quot;Sentra&quot;, &quot;Kicks&quot;, &quot;Juke&quot;, &quot;X-Trail&quot;]),<br>    Car(brand: &quot;Ford&quot;, model: [&quot;Kuga&quot;, &quot;Focus 5D&quot;, &quot;Focus Wagon&quot;, &quot;Focus Active&quot;]),<br>    Car(brand: &quot;Lexus&quot;, model: [&quot;NX&quot;, &quot;RX&quot;, &quot;LBX&quot;, &quot;UX&quot;]),<br>    Car(brand: &quot;M.Benz&quot;, model: [&quot;GLC&quot;, &quot;GLC Coupe&quot;, &quot;GLA&quot;, &quot;C-Class Sedan&quot;]),<br>    Car(brand: &quot;BMW&quot;, model: [&quot;X1&quot;, &quot;X2&quot;, &quot;X3&quot;, &quot;X4&quot;, &quot;X5&quot;]),<br>    Car(brand: &quot;Volkswagen&quot;, model: [&quot;Tiguan&quot;, &quot;Golf&quot;, &quot;T-Roc&quot;, &quot;T-Cross&quot;])<br>]</pre><p>要設定ViewController為PickerView的delegate和data source，在加入extension的程式碼。</p><p>component:0 代表品牌<br>component:1 代表車型</p><pre>var selectedCar: Car = cars[0]//儲存當前選到的資料<br><br>extension ViewController: UIPickerViewDataSource, UIPickerViewDelegate {<br>    func numberOfComponents(in pickerView: UIPickerView) -&gt; Int {<br>        2<br>    }<br>    <br>    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -&gt; Int {<br>        if component == 0 {<br>            return cars.count<br>        } else {<br>            return selectedCar.model.count<br>        }<br>    }<br>    <br>    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -&gt; String? {<br>        if component == 0 {<br>            return cars[row].brand<br>        } else {<br>            return selectedCar.model[row]<br>        }<br>    }<br>    <br>    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {<br>        if component == 0 {<br>            selectedCar = cars[row]<br>            carPickerView.reloadComponent(1) //品牌改變，車型要重新reload顯示對應的資料<br>            carPickerView.selectRow(0, inComponent: 1, animated: true)<br>        }<br>    }<br>}</pre><blockquote><strong>Github:</strong></blockquote><p><a href="https://github.com/ggisfun/PickerView.git">GitHub - ggisfun/PickerView</a></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%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/97-uipickerview-%E7%B7%B4%E7%BF%92-42d71c5e298c">#97 UIPickerView 練習</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/%E8%AE%93-uipickerview-%E5%8F%96%E4%BB%A3%E9%8D%B5%E7%9B%A4%E5%90%A7-%E5%88%A9%E7%94%A8-inputview-inputaccessoryview-5a6cd4a5de78">讓 UIPickerView 取代鍵盤吧 — 利用 inputView &amp; inputAccessoryView</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/25-uipickerview-%E6%97%A5%E6%9C%AC%E5%9C%B0%E5%90%8D%E9%81%B8%E6%93%87-667c41870897">#25 UIPickerView｜日本地名選擇</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=751679756e98" width="1" height="1" alt=""><hr><p><a href="https://medium.com/peter-pan-swift-ios-class/22-uipickerview-%E7%B7%B4%E7%BF%92-%E6%B1%BD%E8%BB%8A%E9%81%B8%E6%93%87-751679756e98">#22 UIPickerView 練習_汽車選擇</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>