Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Last active January 31, 2022 21:11
Show Gist options
  • Select an option

  • Save amosgyamfi/1a5e0dac1afa89c85b411bf0607ec845 to your computer and use it in GitHub Desktop.

Select an option

Save amosgyamfi/1a5e0dac1afa89c85b411bf0607ec845 to your computer and use it in GitHub Desktop.
Use this when you want to create balloons-like screen effect for your app
//
// EchoEffect.swift
// iMessageClone
//
// Created by Amos from Stream on 18.12.2021.
//
import SwiftUI
struct BalloonsEffect: View {
@State private var messageEffect = 0
@State private var moving = false
@State private var chromaRotate = false
var body: some View {
ZStack {
if #available(iOS 15.0, *) {
ZStack {
Image("baloonPurple")
.resizable()
.aspectRatio(contentMode: .fit)
.scaleEffect(0.55)
.zIndex(1)
.offset(y: moving ? -450 : 450)
.rotationEffect(.degrees(moving ? -5 : 5), anchor: moving ? .bottomLeading : .bottom)
Image("baloonGreen")
.resizable()
.aspectRatio(contentMode: .fit)
.scaleEffect(0.25)
.zIndex(4)
.offset(y: moving ? -460 : 460)
.rotationEffect(.degrees(moving ? -15 : 15), anchor: moving ? .bottom : .trailing)
Image("baloonOrangeDark")
.resizable()
.aspectRatio(contentMode: .fit)
.scaleEffect(0.5)
.zIndex(3)
.offset(y: moving ? -480 : 480)
.rotationEffect(.degrees(moving ? 15 : -15), anchor: moving ? .bottom : .trailing)
Image("baloonOrangeLight")
.resizable()
.aspectRatio(contentMode: .fit)
.scaleEffect(0.2)
.zIndex(5)
.offset(y: moving ? -480 : 480)
.rotationEffect(.degrees(moving ? -45 : 15), anchor: moving ? .trailing: .leading)
Image("baloonRed")
.resizable()
.aspectRatio(contentMode: .fit)
.scaleEffect(0.5)
.zIndex(2)
.offset(y: moving ? -600 : 600)
.rotationEffect(.degrees(moving ? 0 : -90), anchor: moving ? .topLeading: .trailing)
}
.blendMode(.screen)
//.hueRotation(.degrees(chromaRotate ? 0 : 200))
.task {
withAnimation(.easeInOut(duration: 6).repeatForever(autoreverses: false)){
moving.toggle()
chromaRotate.toggle()
}
}
} else {
// Fallback on earlier versions
}
HStack {
Spacer()
Text("Send with balloons")
.font(.caption)
.textCase(.uppercase)
}
.frame(width: 330)
}
}
}
struct BalloonsEffect_Previews: PreviewProvider {
static var previews: some View {
BalloonsEffect()
.preferredColorScheme(.dark)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment