【SwiftUI模块】0022、SwiftUI搭建一个带有SVG剪辑和反向遮罩的时尚Twitter启动画面

SwiftUI模块系列 - 已更新22篇
SwiftUI项目 - 已更新2个项目
往期Demo源码下载

技术:SwiftUI、SwiftUI3.0、SVG、Twitter、启动页面
运行环境:
SwiftUI3.0 + Xcode13.4.1 + MacOS12.5 + iPhone Simulator iPhone 13 Pro Max

概述

使用SwiftUI搭建一个带有SVG剪辑和反向遮罩的时尚Twitter启动画面

详细

一、运行效果

请添加图片描述

二、项目结构图

在这里插入图片描述

设置启动的logo和背景颜色

在这里插入图片描述

三、程序实现 - 过程

思路:
1.设置主页
2.添加一个背景
3.通过一个图片和背景进行混合

1.创建一个项目命名为 TwitterShapeAnimation

在这里插入图片描述
在这里插入图片描述

1.1.引入资源文件和颜色

颜色
BG #4FA6DF
Twitter的截图1张
logo2张

在这里插入图片描述

Code

ContentView - 主窗口

主要是展示主窗口Home

//
//  ContentView.swift
//  Shared
//
//  Created by 李宇鸿 on 2022/9/3.
//

import SwiftUI

struct ContentView: View {
    var body: some View {
        SplashScreen()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
            .preferredColorScheme(.dark)
    }
}


struct SplashScreen : View{
    
    @State var splashAnimation: Bool = false

    @Environment(\.colorScheme) var scheme

    
    var body: some View{
        ZStack {

            //我们将简单地使用图像演示的目的....
            Image(scheme == .dark ? "homeDark" :  "home")
                .resizable()
                .aspectRatio(contentMode: .fill)
            
            // 躲在home直到飞溅动画开始…
                .opacity(splashAnimation ? 1 : 0)
            
            Color("BG")
            //屏蔽Twitter SVG图像…
            //从xcode 12,我们可以直接使用svg从资产目录....
                .mask(
                    // 反向掩蔽与弯曲....的帮助
                    
                    Rectangle()
                        .overlay(
                            Image("logo-svg")
                                .resizable()
                                .aspectRatio(contentMode: .fit)
                                .frame(width: 80, height: 80)
                                .scaleEffect(splashAnimation  ? 35: 1)
                                .blendMode(.destinationOut)
                        )

                )
            // 通过手势测试启动效果
//                .onTapGesture{
//                    withAnimation(.easeOut(duration: 0.4), {
//                        splashAnimation.toggle()
//                    })
//                }

        }
        .preferredColorScheme(splashAnimation ? nil: .light)
        .ignoresSafeArea()
        .onAppear{
            DispatchQueue.main.asyncAfter(deadline: .now()+0.4) {
                withAnimation(.easeOut(duration: 0.4), {
                   splashAnimation.toggle()
               })
            }
        }

    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宇夜iOS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值