{"id":32761,"date":"2024-11-01T09:11:21","date_gmt":"2024-11-01T09:11:21","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32761"},"modified":"2024-11-01T11:23:50","modified_gmt":"2024-11-01T11:23:50","slug":"swiftui-style-iphone-app-development-zooming-in-out-of-photos-with-a-19-inch-gesture","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32761\/","title":{"rendered":"SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture"},"content":{"rendered":"<p><body><\/p>\n<p>Mobile applications utilize touch gestures to maximize user experience. Among these, the pinch gesture is an intuitive method that allows users to easily zoom in or out on content by spreading or bringing their fingers together. In this tutorial, we will develop a simple iPhone app using SwiftUI and explain how to implement photo zooming in and out using the pinch gesture.<\/p>\n<h2>1. What is SwiftUI?<\/h2>\n<p>SwiftUI is a revolutionary library announced by Apple in 2019 for developing apps on iOS, macOS, watchOS, and tvOS. It is based on a declarative programming model, providing powerful features that make it easy to compose and manage the UI. Using this library results in cleaner code and allows you to preview the app&#8217;s UI instantly.<\/p>\n<h2>2. Understanding the Pinch Gesture<\/h2>\n<p>The pinch gesture is an event that occurs when a user touches the screen with two fingers and spreads or brings them together. This gesture can be used in various situations and is particularly useful for zooming in and out of images. In SwiftUI, you can implement easy pinch gesture recognition using the <code>.gesture()<\/code> modifier.<\/p>\n<h2>3. Setting Up the Project<\/h2>\n<h3>3.1 Installing Xcode and Creating a New Project<\/h3>\n<p>Xcode provides all the tools necessary for developing apps on macOS. Open Xcode and start a new iOS project. Select &#8216;App&#8217; as the project template and set SwiftUI as the interface.<\/p>\n<h3>3.2 Basic Project Structure<\/h3>\n<p>Let&#8217;s take a look at the basic structure of the generated SwiftUI project. The <code>ContentView.swift<\/code> file represents the basic UI, where we will modify the code to implement the zoom in\/out function for images.<\/p>\n<h2>4. Implementing Image Zooming Functionality<\/h2>\n<p>Now, let\u2019s proceed to implement the feature to zoom in and out on images using the pinch gesture. Add the following code to the <code>ContentView.swift<\/code> file.<\/p>\n<pre><code>import SwiftUI\n\n    struct ContentView: View {\n        @State private var zoomScale: CGFloat = 1.0\n        @State private var lastScale: CGFloat = 1.0\n        \n        var body: some View {\n            let pinchGesture = MagnificationGesture()\n                .onChanged { scale in\n                    self.zoomScale = self.lastScale * scale\n                }\n                .onEnded { scale in\n                    self.lastScale = self.zoomScale\n                }\n            \n            Image(\"your_image_name\")\n                .resizable()\n                .scaledToFit()\n                .scaleEffect(zoomScale)\n                .gesture(pinchGesture)\n                .frame(width: 300, height: 300)\n                .clipped()\n        }\n    }\n\n    struct ContentView_Previews: PreviewProvider {\n        static var previews: some View {\n            ContentView()\n        }\n    }<\/code><\/pre>\n<p>The above code implements the basic logic necessary to zoom in or out on an image using the pinch gesture. It uses the <code>@State<\/code> property wrapper to keep track of the current zoom scale and the last scale value. The <code>MagnificationGesture()<\/code> updates the scale each time the gesture occurs.<\/p>\n<h2>5. Code Explanation<\/h2>\n<p>Let\u2019s go through each part of the implemented code step by step:<\/p>\n<h3>5.1 State Variables<\/h3>\n<p><code>@State private var zoomScale: CGFloat<\/code> stores the current zoom scale of the image. <code>@State private var lastScale: CGFloat<\/code> records the zoom scale last applied by the user.<\/p>\n<h3>5.2 Pinch Gesture<\/h3>\n<p><code>let pinchGesture = MagnificationGesture()<\/code> detects the pinch gesture. The <code>.onChanged<\/code> method is called every time the user swipes with two fingers, updating the current scale. <code>.onEnded<\/code> updates the last scale when the gesture ends.<\/p>\n<h3>5.3 Image View<\/h3>\n<p><code>Image(\"your_image_name\")<\/code> loads an image from the app\u2019s resources. <code>.scaleEffect(zoomScale)<\/code> adjusts the image according to the current zoom scale. <code>.gesture(pinchGesture)<\/code> applies the pinch gesture to the image.<\/p>\n<h2>6. Debugging and Testing<\/h2>\n<p>Now that you have written the code, build the app and test it on a simulator or real device. Check if you can zoom in and out by pressing the image with two fingers.<\/p>\n<h2>7. Implementing Additional Features<\/h2>\n<p>In addition to the basic zooming functionality, you can consider various additional features:<\/p>\n<ul>\n<li><strong>Gesture Improvement:<\/strong> Additional gesture recognition (e.g., rotation)<\/li>\n<li><strong>Limit Setting:<\/strong> Minimum and maximum zoom scale limits<\/li>\n<li><strong>Animation:<\/strong> Add animation effects to zooming in and out<\/li>\n<\/ul>\n<h2>8. Conclusion<\/h2>\n<p>With the powerful features of SwiftUI and declarative programming, we were able to effortlessly implement a photo zooming functionality based on pinch gestures. This feature can be useful in various applications, such as photo gallery apps. Hope to explore more user gestures and UI components to expand the app&#8217;s functionality in the future.<\/p>\n<h2>9. References<\/h2>\n<ul>\n<li><a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\">SwiftUI Documentation<\/a><\/li>\n<li><a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\/gestures\">Gestures in SwiftUI<\/a><\/li>\n<li><a href=\"https:\/\/www.hackingwithswift.com\/plus\/whats-new-in-swiftui\">What&#8217;s New in SwiftUI<\/a><\/li>\n<\/ul>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mobile applications utilize touch gestures to maximize user experience. Among these, the pinch gesture is an intuitive method that allows users to easily zoom in or out on content by spreading or bringing their fingers together. In this tutorial, we will develop a simple iPhone app using SwiftUI and explain how to implement photo zooming &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32761\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[125],"tags":[],"class_list":["post-32761","post","type-post","status-publish","format-standard","hentry","category-swift-iphone-app-development-swiftui"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32761\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Mobile applications utilize touch gestures to maximize user experience. Among these, the pinch gesture is an intuitive method that allows users to easily zoom in or out on content by spreading or bringing their fingers together. In this tutorial, we will develop a simple iPhone app using SwiftUI and explain how to implement photo zooming &hellip; \ub354 \ubcf4\uae30 &quot;SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32761\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:11:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:23:50+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32761\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32761\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture\",\"datePublished\":\"2024-11-01T09:11:21+00:00\",\"dateModified\":\"2024-11-01T11:23:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32761\/\"},\"wordCount\":584,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Swift iPhone app development (SwiftUI)\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32761\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32761\/\",\"name\":\"SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:11:21+00:00\",\"dateModified\":\"2024-11-01T11:23:50+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32761\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32761\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32761\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32761\/","og_locale":"ko_KR","og_type":"article","og_title":"SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Mobile applications utilize touch gestures to maximize user experience. Among these, the pinch gesture is an intuitive method that allows users to easily zoom in or out on content by spreading or bringing their fingers together. In this tutorial, we will develop a simple iPhone app using SwiftUI and explain how to implement photo zooming &hellip; \ub354 \ubcf4\uae30 \"SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture\"","og_url":"https:\/\/atmokpo.com\/w\/32761\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:11:21+00:00","article_modified_time":"2024-11-01T11:23:50+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32761\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32761\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture","datePublished":"2024-11-01T09:11:21+00:00","dateModified":"2024-11-01T11:23:50+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32761\/"},"wordCount":584,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Swift iPhone app development (SwiftUI)"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32761\/","url":"https:\/\/atmokpo.com\/w\/32761\/","name":"SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:11:21+00:00","dateModified":"2024-11-01T11:23:50+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32761\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32761\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32761\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"SwiftUI style, iPhone app development: Zooming in\/out of photos with a 19-inch gesture"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32761"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32761\/revisions"}],"predecessor-version":[{"id":32762,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32761\/revisions\/32762"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}