์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- SwiftUI
- Flutter
- Lv2
- TCA
- BFS
- ํจ์คํธ์บ ํผ์ค
- Xcode
- reactorkit
- ํ๋ก๊ทธ๋๋จธ์ค
- designpattern
- raywenderlich
- ๋ฐฑ์ค
- RxSwift
- CollectionView
- Kuring
- Swfit
- swift
- tableView
- BOJ
- UIKit
- SnapKit
- visionOS
- XCTest
- combine
- realm
- arkit
- MVVM
- rxcocoa
- node.js
- ios
Archives
- Today
- Total
lgvv98
[iOS] ํ๋ฉด ์คํฌ๋ฆฐ์ท ๋ฐ ๋ นํ ๊ฐ์ง (feat. SwiftUI) ๋ณธ๋ฌธ
apple/๐ SwiftUI & Combine
[iOS] ํ๋ฉด ์คํฌ๋ฆฐ์ท ๋ฐ ๋ นํ ๊ฐ์ง (feat. SwiftUI)
๐ฅ ์บ๋ฟ๋งจ 2022. 6. 2. 16:22ํ๋ฉด ์คํฌ๋ฆฐ์ท ๋ฐ ๋ นํ ๊ฐ์ง
โ ํ๋ฉด ๋ นํ ๋ฐ ์คํฌ๋ฆฐ์ท ๊ฐ์ง์ ๋ํด์ ์์๋ด ์๋ค.
์ฐ์ ํ๋ฉด ๋ นํ ๋ฐ ์คํฌ๋ฆฐ์ท์ NotificationCenter๋ฅผ ํตํด ์ ์ ์์ต๋๋ค.
// ํ๋ฉด์บก์ณ
NotificationCenter.default.publisher(for: UIScreen.capturedDidChangeNotification)
// ํ๋ฉด๋
นํ
NotificationCenter.default.publisher(for: UIApplication.userDidTakeScreenshotNotification)
โ ์ฝ๋
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack {
MainView() // ๋ฉ์ธ ์ปจํ
ํธ ๋ทฐ
BlockView() // ๋ธ๋ญ ๋ทฐ
}
}
}
// ์ผ๋ฟ์ฐฝ ๋ฐ์ดํฐ
struct AlertData: Identifiable {
var id: UUID
let title: String
let message: String
init(title: String = "์๋
ํ์ธ์!" , message : String = "์คํฌ๋ฆฐ ์บก์ณ๋ฅผ ํ์
จ๊ตฐ์! ๐ฆ") {
self.id = UUID()
self.title = title
self.message = message
}
}
/// ๋ธ๋ญ ์ฒ๋ฆฌ ๋ทฐ
struct BlockView: View {
// ios ์์คํ
์์๋ ์์คํ
์ด๋ฒคํธ๋ฅผ ์๋ ค์ค๋ค. - ๋
ธํฐํผ์ผ์ด์
์ผํฐ
// ๋
ธํฐํผ์ผ์ด์
-> publisher ๋ก ๋ฐ์์ ์๋ค.
// SwiftUI ์์๋ publisher ์ด๋ฒคํธ๋ฅผ onReceive ๋ก ๋ฐ๋๋ค.
@State private var alertData: AlertData?
// ๋
นํ์ค ์ฌ๋ถ
@State var isRecordingScreen = false
var body: some View {
ZStack {
if isRecordingScreen {
Color.white
Text("ํ๋ฉด ๋
นํ์ค์
๋๋ค! ๐ฅ")
.font(.largeTitle)
.padding()
}
}
.onReceive(NotificationCenter.default.publisher(for: UIScreen.capturedDidChangeNotification), perform: { _ in
print("UIScreen.main.isCaptured : \(UIScreen.main.isCaptured)")
isRecordingScreen = UIScreen.main.isCaptured
print(isRecordingScreen ? "๋
นํ ์์" : "๋
นํ ์ค์ง")
})
.onReceive(NotificationCenter.default.publisher(for: UIApplication.userDidTakeScreenshotNotification), perform: { _ in
print("์คํฌ๋ฆฐ์ท์ด ์ฐ์ด์ก๋ค.")
alertData = AlertData()
})
.edgesIgnoringSafeArea(.all)
.alert(item: $alertData, content: { alertData in
Alert(title: Text(alertData.title),
message: Text(alertData.message),
dismissButton: Alert.Button.cancel(Text("๋ซ๊ธฐ")))
})
}
}
struct MainView: View {
var body: some View {
VStack {
Text("์๋
ํ์ธ์\n๊ฐ๋ฐํ๋ ์ ๋๋ฆฌ ์
๋๋ค! ๐ถ")
.font(.largeTitle)
.foregroundColor(.white)
.padding()
}
.frame(minWidth: 0, maxWidth: .infinity,
minHeight: 0, maxHeight: .infinity,
alignment: .center)
.background(Color.blue)
.edgesIgnoringSafeArea(.all)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
(์ฐธ๊ณ )
https://green1229.tistory.com/176
SwiftUI - NotificationCenter
์๋ ํ์ธ์. ๊ทธ๋ฆฐ์ ๋๋ค๐ข ์ด๋ฒ ํฌ์คํ ์์๋ SwiftUI์์ NotificationCenter๋ฅผ ํ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํด ํ์ตํ๊ฒ ์ต๋๋ค๐ง๐ป๐ป UIKit์์๋ ์ ์๊ฒ ๋๋ฐ ๋์ฒด SwiftUI์์๋ ์ด๋ป๊ฒ ๋ ธํผํฐ์ผ์ด์ ์ผ
green1229.tistory.com
'apple > ๐ SwiftUI & Combine' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SwiftUI] @StateObject (0) | 2022.06.02 |
---|---|
[SwiftUI] State and Data Flow (0) | 2022.06.02 |
[SwiftUI] ViewModifier (0) | 2022.06.02 |
[SwiftUI] lazyVGrid (0) | 2022.05.25 |
[SwiftUI] menu (feat. Picker) (0) | 2022.05.25 |
Comments