A Swift Package that uses Metal shaders to apply a Pokemon-style foil effect to a view.
Add the following dependency to your Package.swift file:
dependencies: [
.package(url: "https://github.com/bpisano/sticker", .upToNextMajor(from: "0.1.0"))
]Use the .stickerEffect() view modifier to apply the effect to any view.
import Sticker
struct ContentView: View {
var body: some View {
Image(.stickerIcon)
.stickerEffect()
}
}By default, the effect is not animated.
The effect can be animated using the .stickerMotionEffect() view modifier.
Image(.stickerIcon)
.stickerEffect()
.stickerMotionEffect(.pointerHover)The following motion effects are available:
| Effect | Description |
|---|---|
.pointerHover |
Apply a 3D transform that looks at the pointer. |
.identity |
Remove the motion effect. |
You can create your own motion effects by implementing the StickerMotionEffect protocol.
struct MyMotionEffect: StickerMotionEffect {
let startDate: Date = .init()
func body(content: Content) -> some View {
// Implement your motion effect here.
// This example applies a sine wave rotation to the content.
TimelineView(.animation) { context in
let elapsedTime = context.date.timeIntervalSince(startDate)
let rotation = sin(elapsedTime * 2) * 10
content
.rotationEffect(.degrees(rotation))
}
}
}
extension StickerMotionEffect where Self == MyMotionEffect {
static var myMotionEffect: Self { .init() }
}