-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new version of core screenshot logic
- Loading branch information
Showing
8 changed files
with
170 additions
and
48 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
14 changes: 0 additions & 14 deletions
14
...enshotableViewExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file was deleted.
Oops, something went wrong.
Binary file modified
BIN
+27.3 KB
(160%)
...eproj/project.xcworkspace/xcuserdata/timo.wang.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
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
75 changes: 75 additions & 0 deletions
75
ScreenshotableViewExample/ScreenshotableViewExample/ScrollScreenshotView.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,75 @@ | ||
// | ||
// ScrollScreenshotView.swift | ||
// ScreenshotableViewExample | ||
// | ||
// Created by Wang Timo on 2024/6/19. | ||
// | ||
|
||
import SwiftUI | ||
import ScreenshotableView | ||
|
||
/// 生成随机颜色 | ||
/// generate random color | ||
extension Color { | ||
static var random: Color { | ||
return Color(red: .random(in: 0...1), | ||
green: .random(in: 0...1), | ||
blue: .random(in: 0...1)) | ||
} | ||
} | ||
|
||
struct ScrollScreenshotView: View { | ||
@State var shotting = false | ||
@State var screenshot: Image? = nil | ||
|
||
let colors = generateRandomColors() | ||
|
||
var body: some View { | ||
VStack(spacing: 40) { | ||
if let screenshot { | ||
Text("Screenshot result ↓") | ||
screenshot | ||
.resizable() | ||
.aspectRatio(contentMode: .fit) | ||
.frame(height: 400) | ||
} else { | ||
Text("Scrollview ↓") | ||
ScreenshotableContent() | ||
.frame(height: 400) | ||
} | ||
|
||
Button("Generate Screenshot") { | ||
shotting.toggle() | ||
} | ||
Button("Clear Screenshot") { | ||
screenshot = nil | ||
} | ||
} | ||
} | ||
|
||
private func ScreenshotableContent() -> some View { | ||
ScreenshotableScrollView(shotting: $shotting) { screenshot in | ||
self.screenshot = Image(uiImage: screenshot) | ||
} content: { style in | ||
VStack { | ||
ForEach(0..<colors.count, id: \.self) { index in | ||
Rectangle() | ||
.fill(colors[index]) | ||
.frame(height: 100) | ||
.padding(2) | ||
} | ||
} | ||
.padding() | ||
.border(.black) | ||
.padding() | ||
} | ||
} | ||
|
||
static func generateRandomColors(count: Int = 10) -> [Color] { | ||
return (0..<count).map { _ in Color.random } | ||
} | ||
} | ||
|
||
#Preview { | ||
ScrollScreenshotView() | ||
} |
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