From 88f66442add5f2093cb1826b2aea36fe51ed2b7a Mon Sep 17 00:00:00 2001 From: Kai Kim Date: Tue, 22 Aug 2023 22:14:08 +0900 Subject: [PATCH] feat: RecruitFeedView Add MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 피드화면 생성 1차 commit (사진등록제외) --- .../project.pbxproj | 24 +++ .../ContentView.swift | 22 ++- .../RecruitFeedView/RecruitFeedMap.swift | 59 +++++++ .../RecruitFeedView/RecruitFeedView.swift | 146 ++++++++++++++++++ .../RecruitFeedViewModel.swift | 38 +++++ 5 files changed, 282 insertions(+), 7 deletions(-) create mode 100644 project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedMap.swift create mode 100644 project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedView.swift create mode 100644 project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedViewModel.swift diff --git a/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer.xcodeproj/project.pbxproj b/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer.xcodeproj/project.pbxproj index 2b59a501..3f59b5b6 100644 --- a/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer.xcodeproj/project.pbxproj +++ b/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer.xcodeproj/project.pbxproj @@ -11,6 +11,9 @@ 9E99CCF02A944A5700699B6A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E99CCEF2A944A5700699B6A /* ContentView.swift */; }; 9E99CCF22A944A5A00699B6A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9E99CCF12A944A5A00699B6A /* Assets.xcassets */; }; 9E99CCF52A944A5A00699B6A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9E99CCF42A944A5A00699B6A /* Preview Assets.xcassets */; }; + B76000792A946E4E00F35291 /* RecruitFeedViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B76000782A946E4E00F35291 /* RecruitFeedViewModel.swift */; }; + B760007B2A946E5900F35291 /* RecruitFeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B760007A2A946E5900F35291 /* RecruitFeedView.swift */; }; + B7610B832A94E3AA0074F78C /* RecruitFeedMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7610B822A94E3AA0074F78C /* RecruitFeedMap.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -19,6 +22,9 @@ 9E99CCEF2A944A5700699B6A /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 9E99CCF12A944A5A00699B6A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 9E99CCF42A944A5A00699B6A /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + B76000782A946E4E00F35291 /* RecruitFeedViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecruitFeedViewModel.swift; sourceTree = ""; }; + B760007A2A946E5900F35291 /* RecruitFeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecruitFeedView.swift; sourceTree = ""; }; + B7610B822A94E3AA0074F78C /* RecruitFeedMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecruitFeedMap.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -53,6 +59,7 @@ children = ( 9E99CCED2A944A5700699B6A /* project02_teamB_OUR_consumerApp.swift */, 9E99CCEF2A944A5700699B6A /* ContentView.swift */, + B76000762A946E1F00F35291 /* RecruitFeedView */, 9E99CCF12A944A5A00699B6A /* Assets.xcassets */, 9E99CCF32A944A5A00699B6A /* Preview Content */, ); @@ -67,6 +74,16 @@ path = "Preview Content"; sourceTree = ""; }; + B76000762A946E1F00F35291 /* RecruitFeedView */ = { + isa = PBXGroup; + children = ( + B76000782A946E4E00F35291 /* RecruitFeedViewModel.swift */, + B760007A2A946E5900F35291 /* RecruitFeedView.swift */, + B7610B822A94E3AA0074F78C /* RecruitFeedMap.swift */, + ); + path = RecruitFeedView; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -138,6 +155,9 @@ buildActionMask = 2147483647; files = ( 9E99CCF02A944A5700699B6A /* ContentView.swift in Sources */, + B760007B2A946E5900F35291 /* RecruitFeedView.swift in Sources */, + B7610B832A94E3AA0074F78C /* RecruitFeedMap.swift in Sources */, + B76000792A946E4E00F35291 /* RecruitFeedViewModel.swift in Sources */, 9E99CCEE2A944A5700699B6A /* project02_teamB_OUR_consumerApp.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -275,11 +295,13 @@ DEVELOPMENT_TEAM = ACJMUH34H4; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "Please allow us to access your location"; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -304,11 +326,13 @@ DEVELOPMENT_TEAM = ACJMUH34H4; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "Please allow us to access your location"; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/ContentView.swift b/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/ContentView.swift index 65ebe052..7e380351 100644 --- a/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/ContentView.swift +++ b/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/ContentView.swift @@ -6,19 +6,27 @@ // import SwiftUI +import MapKit +import CoreLocationUI struct ContentView: View { var body: some View { - VStack { - Image(systemName: "globe") - .imageScale(.large) - .foregroundStyle(.tint) - Text("Hello, world!") + NavigationStack{ + VStack { + RecruitFeedView() + } } .padding() } } -#Preview { - ContentView() + +struct ContentView_Previews: PreviewProvider { + static var previews: some View { + NavigationStack{ + ContentView() + } + } } + + diff --git a/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedMap.swift b/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedMap.swift new file mode 100644 index 00000000..dd5b9004 --- /dev/null +++ b/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedMap.swift @@ -0,0 +1,59 @@ +// +// RecruitFeedMap.swift +// project02-teamB-OUR-consumer +// +// Created by kaikim on 2023/08/22. +// + +import SwiftUI +import CoreLocation +import CoreLocationUI + +class LocationManager: NSObject, ObservableObject { + + private let manager = CLLocationManager() + @Published var userLocation: CLLocation? + static let shared = LocationManager() + var addressString = "" + + override init() { + super.init() + manager.delegate = self + manager.desiredAccuracy = kCLLocationAccuracyBest + manager.startUpdatingLocation() + } + + func requestLocation() { + manager.requestWhenInUseAuthorization() + } + +} + +extension LocationManager: CLLocationManagerDelegate { + func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { + + switch status { + + case .notDetermined: + print("DEBUG: Not Determined") + case .restricted: + print("DEBUG: Restricted") + case .denied: + print("DEBUG: Denied") + case .authorizedAlways: + print("DEBUG: Auth always") + case .authorizedWhenInUse: + print("DEBUG: AUTH when in use") + @unknown default: + break + } + } + + func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + guard let location = locations.last else { return} + self.userLocation = location + + } + + +} diff --git a/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedView.swift b/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedView.swift new file mode 100644 index 00000000..34ee0aba --- /dev/null +++ b/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedView.swift @@ -0,0 +1,146 @@ +// +// RecruitFeedView.swift +// project02-teamB-OUR-consumer +// +// Created by kaikim on 2023/08/22. +// + +import SwiftUI +import MapKit +import CoreLocationUI +import CoreLocation + +struct RecruitFeedView: View { + + @StateObject var locationManager = LocationManager.shared + + //임시적 변수(취소,등록) + @State var toolbarToogle:Bool = false + @State var privacySetting:PrivacySetting = PrivacySetting.Public + @State var contentText:String = "" + @State var placeholder:String = "Share Your Idea In OUR." + @State var address: String = "" + var body: some View { + + NavigationStack { + ScrollView{ + VStack(alignment: .leading){ + HStack{ + Picker("PrivacySetting", selection: $privacySetting) { + Text("Public").tag(PrivacySetting.Public) + Text("Private").tag(PrivacySetting.Private) + } + .pickerStyle(.menu) + Spacer() + } + + //현재위치설정 버튼 + LocationButton(.currentLocation) { + locationManager.requestLocation() + + } + //위치설명 버튼 + Button { + convertLocationToAddress(location: locationManager.userLocation!) + } label: { + address.isEmpty ? Text("위치설명 버튼") : Text("\(address)") + } + + } + .padding() + + ZStack{ + TextEditor(text: $contentText) + .frame(minHeight:300, maxHeight:350) + .buttonBorderShape(.roundedRectangle) + .border(Color.secondary) + + if contentText.isEmpty { + Text(placeholder) + .foregroundColor(.secondary) + } + } + + Spacer() + Section("Add Photo") { + + + HStack{ + Button(action: { + + }, label: { + Image(systemName: "plus") + .frame(width: 100,height: 100) + .buttonBorderShape(.roundedRectangle) + .border(Color.secondary) + }) + + + Button(action: { + + }, label: { + Image(systemName: "plus") + .frame(width: 100,height: 100) + .buttonBorderShape(.roundedRectangle) + .border(Color.secondary) + }) + + + Button(action: { + + }, label: { + Image(systemName: "plus") + .frame(width: 100,height: 100) + .buttonBorderShape(.roundedRectangle) + .border(Color.secondary) + }) + + + } + .buttonBorderShape(.roundedRectangle) + .border(Color.secondary) + } + Spacer() + + + } + .toolbar { + ToolbarItem(placement:.navigationBarLeading) { + Button("취소") { + toolbarToogle.toggle() + } + } + ToolbarItem(placement:.navigationBarTrailing) { + Button("등록") { + toolbarToogle.toggle() + } + } + + } + } + } + func convertLocationToAddress(location: CLLocation) { + //"en_US_POSIX" + let geocoder = CLGeocoder() + let locale = Locale(identifier: "ko-KR") + geocoder.reverseGeocodeLocation(location, preferredLocale: locale) { (placemarks,error) in + if error != nil { + return + } + guard let placemark = placemarks?.first else {return} + + self.address = "\(placemark.country ?? "") \(placemark.locality ?? "") \(placemark.name ?? "")" + } + } +} + +struct RecruitFeedView_Previews: PreviewProvider { + static var previews: some View { + NavigationStack{ + RecruitFeedView() + } + } +} + + + diff --git a/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedViewModel.swift b/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedViewModel.swift new file mode 100644 index 00000000..d0984c85 --- /dev/null +++ b/project02-teamB-OUR-consumer/project02-teamB-OUR-consumer/RecruitFeedView/RecruitFeedViewModel.swift @@ -0,0 +1,38 @@ +// +// RecruitFeedViewModel.swift +// project02-teamB-OUR-consumer +// +// Created by kaikim on 2023/08/22. +// + +import Foundation + + +//아직 모델은 고민중 +struct RecruitFeedViewModel { + + var privacySetting: Bool + var title: String + var content: String + //var location: 뭐로할까 + //var photo: Image 뭐로할까 + var dateWriting: Date + +} + +//전체범위 공개 enum 처리 +enum PrivacySetting { + + case Public + case Private + + // 각 case에 맞게 가격을 화면에 보여주기 위해 + var setting: String { + switch self { + case .Public: + return "Public" + case .Private: + return "Private" + } + } +}