From 6b82005001a3cf1265408bf5548d26cc7980a8e7 Mon Sep 17 00:00:00 2001 From: jeonjimin Date: Fri, 23 Jun 2023 17:34:05 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20#122=20-=20=ED=97=A4=EB=8D=94=20?= =?UTF-8?q?=EC=A0=84=ED=99=98=20=EA=B8=B0=EB=8A=A5=20=EA=B8=B0=EA=B8=B0=20?= =?UTF-8?q?=EB=8C=80=EC=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 각 기기별 화면 크기에 따라 전환 효과가 나타나야할 아이템 개수가 달라지므로 기기 화면 높이와 아이템 높이로 계산하여 전환 효과 조건 지정함 --- Halmap.xcodeproj/project.pbxproj | 4 -- Halmap/Extensions/CustomCorner.swift | 17 ----- Halmap/View/ScalingHeaderView.swift | 104 ++++++++++++++++----------- 3 files changed, 62 insertions(+), 63 deletions(-) delete mode 100644 Halmap/Extensions/CustomCorner.swift diff --git a/Halmap.xcodeproj/project.pbxproj b/Halmap.xcodeproj/project.pbxproj index af8e7ad..7c2c569 100644 --- a/Halmap.xcodeproj/project.pbxproj +++ b/Halmap.xcodeproj/project.pbxproj @@ -55,7 +55,6 @@ F9B3B7B729B842DD00232BB8 /* SongDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9B3B7B629B842DD00232BB8 /* SongDetailView.swift */; }; F9B95BB928F271A100728048 /* DataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9B95BB828F271A100728048 /* DataManager.swift */; }; F9B95BBB28F271B800728048 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9B95BBA28F271B800728048 /* Model.swift */; }; - F9DAABB02A4190A4001168A9 /* CustomCorner.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9DAABAF2A4190A4001168A9 /* CustomCorner.swift */; }; F9E4642329E8089A009E12FC /* ScalingHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9E4642229E8089A009E12FC /* ScalingHeaderView.swift */; }; F9EB19C129168E45002DFE46 /* Song.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9EB19BD29168336002DFE46 /* Song.swift */; }; /* End PBXBuildFile section */ @@ -107,7 +106,6 @@ F9B3B7B629B842DD00232BB8 /* SongDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SongDetailView.swift; sourceTree = ""; }; F9B95BB828F271A100728048 /* DataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataManager.swift; sourceTree = ""; }; F9B95BBA28F271B800728048 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; - F9DAABAF2A4190A4001168A9 /* CustomCorner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCorner.swift; sourceTree = ""; }; F9E4642229E8089A009E12FC /* ScalingHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScalingHeaderView.swift; sourceTree = ""; }; F9EB19BD29168336002DFE46 /* Song.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Song.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -223,7 +221,6 @@ 87F6ECF0291677AC004533C4 /* Halmap+UIApplication.swift */, 87F6ECF42916B331004533C4 /* Halmap+UINavigationController.swift */, 87F6ECF62916BB44004533C4 /* Halmap+UIView.swift */, - F9DAABAF2A4190A4001168A9 /* CustomCorner.swift */, ); path = Extensions; sourceTree = ""; @@ -392,7 +389,6 @@ A81FFCA728F1B84A00B0FC7C /* Halmap+Color.swift in Sources */, F98F622929B4C9BD0025F50E /* Themes.swift in Sources */, 20317FB228F2CCBB00A30E09 /* TeamChangingView.swift in Sources */, - F9DAABB02A4190A4001168A9 /* CustomCorner.swift in Sources */, A81FFC7A28F15D9900B0FC7C /* HalmapApp.swift in Sources */, F91BE5FD29B18D1E00F7E488 /* MainSongListTabView.swift in Sources */, F939EBBA29D58FB2005ED8CA /* StorageContentView.swift in Sources */, diff --git a/Halmap/Extensions/CustomCorner.swift b/Halmap/Extensions/CustomCorner.swift deleted file mode 100644 index 301a339..0000000 --- a/Halmap/Extensions/CustomCorner.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// CustomCorner.swift -// Halmap -// -// Created by JeonJimin on 2023/06/20. -// - -import SwiftUI - -struct CustomCorner: Shape { - var corners: UIRectCorner - func path(in rect: CGRect) -> Path { - let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: 35, height: 35)) - - return Path(path.cgPath) - } -} diff --git a/Halmap/View/ScalingHeaderView.swift b/Halmap/View/ScalingHeaderView.swift index d1adb5c..534f400 100644 --- a/Halmap/View/ScalingHeaderView.swift +++ b/Halmap/View/ScalingHeaderView.swift @@ -9,12 +9,13 @@ import SwiftUI struct ScalingHeaderView: View { @EnvironmentObject var dataManager: DataManager - let maxHeight: CGFloat = 216 + let maxHeight: CGFloat = UIScreen.getHeight(216) var topEdge: CGFloat @State var offset: CGFloat = 0 @State var isShowSheet = false @State var collectedSongData: CollectedSong? + @State var isDraged = false @FetchRequest(entity: CollectedSong.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \CollectedSong.date, ascending: true)], predicate: PlayListFilter(filter: "favorite").predicate, animation: .default) private var collectedSongs: FetchedResults @@ -25,28 +26,43 @@ struct ScalingHeaderView: View { VStack(spacing: 15) { GeometryReader { proxy in VStack(spacing: 0) { - TopBar(topEdge: topEdge, offset: $offset) + topBar .frame(maxWidth: .infinity) .frame(height: getHeaderHeight(), alignment: .bottom) .overlay( topTitle - .opacity(topTitleOpacity()) + .opacity(checkScrollRequirement(listCount: collectedSongs.count) && isDraged ? 1 : 0) ) HStack() { Text("총 \(collectedSongs.count)곡") .font(Font.Halmap.CustomCaptionBold) .foregroundColor(.customDarkGray) Spacer() + Button { + withAnimation { + isDraged.toggle() + } + } label: { + HStack(spacing: 5) { + Image(systemName: "play.circle.fill") + .foregroundColor(.mainGreen) + .font(.system(size: 20)) + Text("전체 재생하기") + .font(Font.Halmap.CustomCaptionBold) + .foregroundColor(.mainGreen) + } + .opacity(checkScrollRequirement(listCount: collectedSongs.count) && isDraged ? 1 : 0) + } } .padding(.horizontal, 20) - .padding(.vertical, 17) + .padding(.vertical, UIScreen.getHeight(17)) Divider() .overlay(Color.customGray.opacity(0.6)) .padding(.horizontal, 20) } .background(Color.systemBackground) } - .frame(height: maxHeight + 48) + .frame(height: maxHeight + UIScreen.getHeight(48)) .offset(y: -offset) .zIndex(1) @@ -125,10 +141,48 @@ struct ScalingHeaderView: View { } } .modifier(OffsetModifier(offset: $offset)) + .onChange(of: offset) { _ in + if offset > -UIScreen.getHeight(90) { + withAnimation { + isDraged = false + } + } else if offset < 0 { + withAnimation { + isDraged = true + } + } + } } .coordinateSpace(name: "StorageScroll") .background(Color.systemBackground) + } + + var topBar: some View { + ZStack(alignment: .bottom) { + Image("storageTop") + .resizable() + HStack { + Text("보관함") + .font(Font.Halmap.CustomLargeTitle) + Spacer() + Button { + withAnimation { + isDraged.toggle() + } + } label: { + Image(systemName: "play.circle.fill") + .foregroundColor(.mainGreen) + .font(.system(size: 50)) + } + } + .padding(EdgeInsets(top: 0, leading: 20, bottom: 20, trailing: 20)) + } + .opacity(checkScrollRequirement(listCount: collectedSongs.count) && isDraged ? 0 : 1) + .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom) + .background(Color.systemBackground) + } + var topTitle: some View { VStack{ HStack { @@ -143,45 +197,11 @@ struct ScalingHeaderView: View { } func getHeaderHeight() -> CGFloat { - let topHeight = maxHeight + offset - - return topHeight >= (59 + topEdge) ? topHeight : (59 + topEdge) + isDraged ? (59 + topEdge) : maxHeight + offset } - func topTitleOpacity() -> CGFloat { - let progress = -offset*2 / (maxHeight - (59 + topEdge)) - return progress - } - func getOpacity() -> CGFloat { - let progress = -offset*2 / 40 - let opacity = 1 - progress - return offset < 0 ? opacity : 1 - } -} - -struct TopBar: View { - - let topEdge: CGFloat - @Binding var offset: CGFloat - var body: some View { - ZStack(alignment: .bottom) { - Image("storageTop") - .resizable() - HStack { - Text("보관함") - .font(Font.Halmap.CustomLargeTitle) - Spacer() - } - .padding(EdgeInsets(top: 0, leading: 20, bottom: 20, trailing: 20)) - } - .opacity(getOpacity()) - .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom) - .background(Color.systemBackground) - } - func getOpacity() -> CGFloat { - let progress = -offset / 40 - let opacity = 1 - progress - return offset < 0 ? opacity : 1 + func checkScrollRequirement(listCount: Int) -> Bool{ + UIScreen.screenHeight - (59 + topEdge) - CGFloat(75 * listCount) <= 0 ? true : false } }