-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] #150 - 로딩 뷰 구현
- Loading branch information
Showing
12 changed files
with
127 additions
and
15 deletions.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
HealthFoodMe/HealthFoodMe/Global/Resources/Lottie/loading_iOS.json
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
86 changes: 86 additions & 0 deletions
86
HealthFoodMe/HealthFoodMe/Presentation/Common/HelfmeLoading/View/HelfmeLoadingView.swift
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,86 @@ | ||
// | ||
// HelfmeLoadingVC.swift | ||
// HealthFoodMe | ||
// | ||
// Created by 강윤서 on 2022/07/20. | ||
// | ||
|
||
import UIKit | ||
|
||
import Lottie | ||
import SnapKit | ||
|
||
class HelfmeLoadingView: UIView { | ||
|
||
// MARK: - Properties | ||
|
||
static let shared = HelfmeLoadingView() | ||
|
||
// MARK: - UI Components | ||
|
||
private var contentView: UIView = { | ||
let view = UIView() | ||
return view | ||
}() | ||
|
||
private var loadingView: AnimationView = { | ||
let animationView = AnimationView(name: "loading_iOS") | ||
animationView.loopMode = .loop | ||
|
||
return animationView | ||
}() | ||
|
||
// MARK: - View Life Cycle | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setLayout() | ||
setUI() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} | ||
|
||
// MARK: - Extension | ||
|
||
extension HelfmeLoadingView { | ||
private func setLayout() { | ||
self.addSubview(contentView) | ||
contentView.addSubview(self.loadingView) | ||
|
||
self.contentView.snp.makeConstraints { | ||
$0.center.equalTo(self.safeAreaLayoutGuide) | ||
} | ||
self.loadingView.snp.makeConstraints { | ||
$0.center.equalTo(self.safeAreaLayoutGuide) | ||
} | ||
} | ||
|
||
private func setUI() { | ||
self.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.4) | ||
} | ||
|
||
func show() { | ||
guard let window = UIApplication.shared.windows.last else { return } | ||
print("윈도우", window) | ||
window.addSubview(self) | ||
|
||
self.snp.makeConstraints { | ||
$0.edges.equalToSuperview() | ||
} | ||
self.layoutIfNeeded() | ||
self.loadingView.play() | ||
UIView.animate( | ||
withDuration: 0.7, | ||
animations: { self.contentView.alpha = 1 } | ||
) | ||
} | ||
|
||
func hide(completion: @escaping () -> ()) { | ||
self.loadingView.stop() | ||
self.removeFromSuperview() | ||
completion() | ||
} | ||
} |
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
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