SwiftUI-抖音Logo動畫

案列展示

macos_wechat_clone_show.gif

案例源碼

import SwiftUI

struct ContentView: View {
    
    let blue = Color(red: 0, green: 255/255.0, blue: 255/255.0)
    let red = Color(red: 255/255.0, green: 24/255.0, blue: 84/255.0)
    let ratio: CGFloat = 1.2
    
    @State private var isRightSide: Bool = true
    
    var body: some View {
        
        ZStack {
            RoundedRectangle(cornerRadius: 25.0)
                .frame(width: 300, height: 300)
                .foregroundColor(.black)
            
            ZStack {
                DouYinShape()
                    .frame(width: 200, height: 200 * ratio)
                    .foregroundColor(red)
                
                DouYinShape()
                    .frame(width: 200, height: 200 * ratio)
                    .foregroundColor(blue)
                    .offset(x: -10.0, y: -10.0)
                
                DouYinShape()
                    .frame(width: 200, height: 200 * ratio)
                    .foregroundColor(.white)
                    .mask(
                        DouYinShape()
                            .frame(width: 200, height: 200 * ratio)
                            .foregroundColor(blue)
                            .offset(x: -10.0, y: -10.0)
                    )
            }
            .rotationEffect(.degrees(isRightSide ? 2 : -2), anchor: UnitPoint(x: 0.5, y: 1))
            .animation(.easeInOut(duration: 0.1).repeatForever(autoreverses: true))
            .onAppear() {
                isRightSide.toggle()
            }
            
            Text("@Super V")
                .font(.title)
                .foregroundColor(.gray)
                .offset(y: 250)
        }
    }
}

struct DouYinShape: Shape {
    func path(in rect: CGRect) -> Path {
        var path = Path()
        let part = rect.maxX / 21
        path.move(to: CGPoint(x: rect.maxX - part * 10, y: rect.minY))
        path.addLine(to: CGPoint(x: rect.maxX, y: rect.minY))
        path.addRelativeArc(center: CGPoint(x: rect.maxX, y: rect.minY), radius: part * 6, startAngle: .degrees(-180), delta: .degrees(-90))
        path.addRelativeArc(center: CGPoint(x: rect.maxX, y: rect.minY), radius: part * 10, startAngle: .degrees(90), delta: .degrees(38))
        
        path.addLine(to: CGPoint(x: rect.maxX - (part * 6), y: rect.maxY - (part * 7)))
        path.addRelativeArc(center: CGPoint(x: rect.minX + (part * 7.5), y: rect.maxY - (part * 7.5)), radius: part * 7.5, startAngle: .degrees(0), delta: .degrees(278))
        path.addRelativeArc(center: CGPoint(x: rect.minX + (part * 7.5), y: rect.maxY - (part * 7.5)), radius: part * 3.5, startAngle: .degrees(-75), delta: .degrees(-(360-75)))
        
        path.closeSubpath()
        return path
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容