-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from MC1-morning-coffee/feat/coffee/interactio…
…nView/14 chore: 코드 병합
- Loading branch information
Showing
4 changed files
with
194 additions
and
93 deletions.
There are no files selected for viewing
92 changes: 0 additions & 92 deletions
92
.swiftpm/xcode/xcshareddata/xcschemes/runSomeWhere.xcscheme
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
// | ||
// SwiftUIView.swift | ||
// | ||
// | ||
// Created by Yun Dongbeom on 2023/03/30. | ||
// | ||
|
||
import SwiftUI | ||
|
||
enum EnumBackgrundImage: CaseIterable { | ||
case opening | ||
case sequence1 | ||
case sequence3 | ||
case ending | ||
} | ||
|
||
extension EnumBackgrundImage { | ||
var srcName: String { | ||
switch self { | ||
case .opening: | ||
return "Background_Image1" | ||
case .sequence1: | ||
return "Background_Image2" | ||
case .sequence3: | ||
return "Background_Image3" | ||
case .ending: | ||
return "Background_Ending" | ||
} | ||
} | ||
|
||
var imgHeight: Int { | ||
switch self { | ||
case .opening: | ||
return 650 | ||
case .sequence1, .sequence3: | ||
return 2600 | ||
case .ending: | ||
return 2500 | ||
} | ||
} | ||
} | ||
|
||
struct SceneBackgroundView: View { | ||
|
||
@EnvironmentObject | ||
var globalStore: GlobalStore | ||
|
||
@State | ||
private var isBlurActive = true | ||
|
||
@State | ||
var currentBg: EnumBackgrundImage = .opening { | ||
didSet { | ||
currentSceneHeight = currentBg.imgHeight | ||
currentSceneImage = currentBg.srcName | ||
} | ||
} | ||
|
||
@State | ||
private var currentSceneHeight = 0 | ||
|
||
@State | ||
private var bgOffsetY = 0 | ||
|
||
@State | ||
private var animationDuration = 3.0 | ||
|
||
@State | ||
private var currentSceneImage = "" { | ||
didSet { | ||
print("currentSceneImage is ", currentSceneImage) | ||
} | ||
} | ||
|
||
|
||
@State | ||
private var isLastScript = false | ||
|
||
func handleCurrentBackground(scriptCount: Int) { | ||
switch globalStore.currentScene { | ||
case .opeaning: | ||
currentBg = .opening | ||
if scriptCount == 3 { | ||
isBlurActive = false | ||
} | ||
if scriptCount == 12 { | ||
globalStore.turnOffIsTapAble() | ||
setTimeoutClosure(timeCount: 400) { | ||
isBlurActive = true | ||
} | ||
setTimeoutClosure(timeCount: 1000) { | ||
globalStore.turnOnIsTapAble() | ||
} | ||
} | ||
case .sequence1: | ||
currentBg = .sequence1 | ||
if scriptCount == 0 { | ||
setTimeoutClosure(timeCount: 400) { | ||
isBlurActive = false | ||
} | ||
} | ||
if scriptCount == 1 { | ||
bgOffsetY = 200 | ||
} | ||
if scriptCount == 10 { | ||
globalStore.turnOffIsTapAble() | ||
setTimeoutClosure(timeCount: 400) { | ||
isBlurActive = true | ||
animationDuration = 0 | ||
} | ||
setTimeoutClosure(timeCount: 500) { | ||
globalStore.turnOffIsFaceViewActive() | ||
} | ||
setTimeoutClosure(timeCount: 1000) { | ||
|
||
globalStore.turnOnIsTapAble() | ||
} | ||
} | ||
case .sequence2: | ||
if scriptCount == 0 { | ||
bgOffsetY = 0 | ||
globalStore.turnOffIsPopupActive() | ||
setTimeoutClosure(timeCount: 400) { | ||
isBlurActive = false | ||
animationDuration = 3.0 | ||
} | ||
} | ||
|
||
if scriptCount == 3 { | ||
globalStore.turnOnIsPopupActive() | ||
} | ||
|
||
case .sequence3: | ||
currentBg = .sequence3 | ||
if scriptCount == 0 { | ||
bgOffsetY = 0 | ||
} | ||
case .ending: | ||
currentBg = .ending | ||
if scriptCount == 0 { | ||
bgOffsetY = 0 | ||
setTimeoutClosure(timeCount: 100) { | ||
globalStore.turnOffIsTapAble() | ||
animationDuration = 12 | ||
bgOffsetY = 2500 - 650 | ||
} | ||
setTimeoutClosure(timeCount: 12000) { | ||
globalStore.turnOnIsTapAble() | ||
} | ||
} | ||
if scriptCount == 6 { | ||
isBlurActive = true | ||
} | ||
if scriptCount == 7 { | ||
isLastScript = true | ||
} | ||
} | ||
} | ||
|
||
var body: some View { | ||
ZStack(alignment: .bottom){ | ||
|
||
/** | ||
실제 배경 이미지 | ||
*/ | ||
Image(currentSceneImage) | ||
.resizable() | ||
.aspectRatio(contentMode: .fill) | ||
.frame(width: 390, height: 650, alignment: .bottom) | ||
.offset(y: CGFloat(bgOffsetY)) | ||
.animation(.linear(duration: animationDuration), value: bgOffsetY) | ||
.alignmentGuide(.bottom) { d in | ||
d[.bottom] | ||
} | ||
/** | ||
가려지는 레이어 | ||
*/ | ||
Rectangle() | ||
.zIndex(100) | ||
.background(isLastScript ? Color.white : Color.black) | ||
.frame(width: CGFloat(390), height: 650) | ||
.opacity(isBlurActive ? 1 : 0) | ||
.animation(.easeInOut(duration: 1), value: isBlurActive) | ||
} | ||
.edgesIgnoringSafeArea(.all) | ||
.onReceive(globalStore.$scriptCount, perform: { currentCount in | ||
handleCurrentBackground(scriptCount: currentCount) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters