当前位置: 首页 > news >正文

wordpress 内容模板下载失败广州seo网站多少钱

wordpress 内容模板下载失败,广州seo网站多少钱,网站怎么让百度收录一张图做封面,中核二三公司最新招聘概述 在 SwiftUI 中,我们可以借助渐变色(Gradient)来实现更加灵动多彩的着色效果。从 SwiftUI 6.0 开始,苹果增加了全新的网格渐变色让我们对其有了更自由的定制度。 因为 gif 格式图片自身的显示能力有限,所以上面的…

在这里插入图片描述

概述

在 SwiftUI 中,我们可以借助渐变色(Gradient)来实现更加灵动多彩的着色效果。从 SwiftUI 6.0 开始,苹果增加了全新的网格渐变色让我们对其有了更自由的定制度。

在这里插入图片描述

因为 gif 格式图片自身的显示能力有限,所以上面的动图无法传神的还原实际的美妙效果。强烈建议大家在模拟器或真机上运行本文中的示例代码。

在本篇博文中,您将学到如下内容:

  • 概述
  • 1. 渐变色的前世今生
  • 2. 动画加持,美轮美奂
  • 3. 综合运用
  • 总结

闲言少叙,让我们马上进入渐变色的世界吧!

Let‘s dive in!!!😉


1. 渐变色的前世今生

在 SwiftUI 中小伙伴们时常会用渐变色(或称为阶梯色)来装扮我们的界面。

在这里插入图片描述

在 SwiftUI 1.0(iOS 13)中有 3 种渐变色类型,它们分别是:线性渐变色 LinearGradient、辐射渐变色 RadialGradient、以及角度渐变色 AngularGradient。

在这里插入图片描述

关于使用它们对进行任意视图裁剪的进一步介绍,请小伙伴们移步如下链接观赏精彩的内容:

  • SwiftUI用Gradient颜色裁剪任意视图

而在 SwiftUI 3.0(iOS 15)中,苹果又添加了一款椭圆渐变色 EllipticalGradient:

在这里插入图片描述

为了能够更加轻松的使用单一颜色的渐变色,苹果从 SwiftUI 4.0(iOS 16)开始干脆将其直接“融入”到 Color 的实例中去了:

在这里插入图片描述

我们可以这样使用它:

Text("Hello Panda").foregroundStyle(.red.gradient)

在 WWDC 24 中,苹果再接再厉为 SwiftUI 6.0(iOS 18)添加了全新渐变色风格:网格渐变色(MeshGradient ):

在这里插入图片描述

别被它的名字所吓到,其实它只是用纵横交错的方格来进一步细粒度控制颜色渐变的自由度,仅此而已。

使用网格渐变色很简单,我们只需创建一个 MeshGradient 实例即可:

MeshGradient(width: 2,height: 2,points: [.init(x: 0, y: 0),.init(x: 1, y: 0), .init(x: 0, y: 1), .init(x: 1, y: 1)],colors: [.red, .green, .blue, .yellow])

如上代码所示:我们创建了一个 2 x 2 网格渐变色,并将其左上角、右上角、左下角、右下角的颜色依次设置为红色、绿色、蓝色以及黄色:

在这里插入图片描述

现在我们“静如处子”的网格渐变色貌似略显“呆滞”。别急,通过适当地调整其内部各个网格边框的基准点(或者颜色),我们可以让它行云流水般的“动如脱兔”。

2. 动画加持,美轮美奂

上面说过,要想动画网格渐变色很简单。我们只需使用若干状态来实时的描述 MeshGradient 中每个网格边框的相对位置以及网格内的颜色即可。

首先,我们创建一个 positions 数组来表示每个网格的边框,注意这是一个 3 x 3 网格:

@State var positions: [SIMD2<Float>] = [.init(x: 0, y: 0), .init(x: 0.2, y: 0), .init(x: 1, y: 0),.init(x: 0, y: 0.7), .init(x: 0.1, y: 0.5), .init(x: 1, y: 0.2),.init(x: 0, y: 1), .init(x: 0.9, y: 1), .init(x: 1, y: 1)]

接下来,我们利用定时器连续调整 positions 里所有非顶角网格边框的相对位置。排除顶角网格的原因是:我们不想让整个网格渐变色在顶点被裁剪:

在这里插入图片描述

具体实现代码如下所示:

let timer = Timer.publish(every: 1/9, on: .current, in: .common).autoconnect()let colors: [Color] = [.purple, .red, .yellow,.blue, .green, .orange,.indigo, .teal, .cyan
]func randomizePosition(currentPosition: SIMD2<Float>,xRange: (min: Float, max: Float),yRange: (min: Float, max: Float)
) -> SIMD2<Float> {let updateDistance: Float = 0.01let newX = if Bool.random() {min(currentPosition.x + updateDistance, xRange.max)} else {max(currentPosition.x - updateDistance, xRange.min)}let newY = if Bool.random() {min(currentPosition.y + updateDistance, yRange.max)} else {max(currentPosition.y - updateDistance, yRange.min)}return .init(x: newX, y: newY)
}MeshGradient(width: 3,height: 3,points: positions,colors: colors).animation(.bouncy, value: positions).onReceive(timer, perform: { _ inpositions[1] = randomizePosition(currentPosition: positions[1],xRange: (min: 0.2, max: 0.9),yRange: (min: 0, max: 0))positions[3] = randomizePosition(currentPosition: positions[3],xRange: (min: 0, max: 0),yRange: (min: 0.2, max: 0.8))positions[4] = randomizePosition(currentPosition: positions[4],xRange: (min: 0.3, max: 0.8),yRange: (min: 0.3, max: 0.8))positions[5] = randomizePosition(currentPosition: positions[5],xRange: (min: 1, max: 1),yRange: (min: 0.1, max: 0.9))positions[7] = randomizePosition(currentPosition: positions[7],xRange: (min: 0.1, max: 0.9),yRange: (min: 1, max: 1))}).animation(.bouncy, value: positions).ignoresSafeArea()

编译并在 Xcode 预览中运行一见分晓:

在这里插入图片描述

再次重申:上面动图“颗粒感”很强是因为 gif 图片本身对颜色限制(最多显示 256 种颜色)的原因,实际效果会相当丝滑顺畅。

现在,我们不但可以恣意描绘静态渐变色,利用些许动画我们还可以让它活灵活现的呈现效果“秾姿故薰欲醉眼,芳信暗传尝苦心”。棒棒哒!💯


想要系统学习最新 Swift 语言如何美美哒的进行苹果开发的小伙伴们,可以到我的《Swift语言开发精讲》专栏来逛一逛哦:

在这里插入图片描述

  • Swift 语言开发精讲

3. 综合运用

下面是一个将网格渐变色溶入到我们实际应用中的演示代码。在代码中我们做了这样几件事:

  • 用不同状态控制不同的动画效果
  • 使用 mask 将网格渐变色嵌入到文本视图中
  • 扩展 View 以实现更简洁的视图方法

全部源代码在此:

import SwiftUIextension View {@ViewBuilderfunc scaleEffect(_ ratio: CGFloat) -> some View {scaleEffect(x: ratio, y: ratio)}
}struct ContentView: View {@State var bgAnimStart = false@State var shadowAnimStart = false@State var positions: [SIMD2<Float>] = [.init(x: 0, y: 0), .init(x: 0.2, y: 0), .init(x: 1, y: 0),.init(x: 0, y: 0.7), .init(x: 0.1, y: 0.5), .init(x: 1, y: 0.2),.init(x: 0, y: 1), .init(x: 0.9, y: 1), .init(x: 1, y: 1)]let timer = Timer.publish(every: 1/9, on: .current, in: .common).autoconnect()let colors1: [Color] = [.purple, .red, .yellow,.blue, .green, .orange,.indigo, .teal, .cyan]let colors2: [Color] = [.black, .red, .blue,.black, .teal, .blue,.blue, .red, .black]func randomizePosition(currentPosition: SIMD2<Float>,xRange: (min: Float, max: Float),yRange: (min: Float, max: Float)) -> SIMD2<Float> {let updateDistance: Float = 0.01let newX = if Bool.random() {min(currentPosition.x + updateDistance, xRange.max)} else {max(currentPosition.x - updateDistance, xRange.min)}let newY = if Bool.random() {min(currentPosition.y + updateDistance, yRange.max)} else {max(currentPosition.y - updateDistance, yRange.min)}return .init(x: newX, y: newY)}func createMeshGradientView(_ colors: [Color]) -> some View {MeshGradient(width: 3,height: 3,points: positions,colors: colors).animation(.bouncy, value: positions).onReceive(timer, perform: { _ inpositions[1] = randomizePosition(currentPosition: positions[1],xRange: (min: 0.2, max: 0.9),yRange: (min: 0, max: 0))positions[3] = randomizePosition(currentPosition: positions[3],xRange: (min: 0, max: 0),yRange: (min: 0.2, max: 0.8))positions[4] = randomizePosition(currentPosition: positions[4],xRange: (min: 0.3, max: 0.8),yRange: (min: 0.3, max: 0.8))positions[5] = randomizePosition(currentPosition: positions[5],xRange: (min: 1, max: 1),yRange: (min: 0.1, max: 0.9))positions[7] = randomizePosition(currentPosition: positions[7],xRange: (min: 0.1, max: 0.9),yRange: (min: 1, max: 1))})}let text = Text("Hello Panda").font(.system(size: 108, weight: .heavy, design: .rounded)).foregroundStyle(.red.gradient)var body: some View {NavigationStack {ZStack {createMeshGradientView(colors1)//.blur(radius: 30.0).opacity(0.8)text.frame(maxWidth: .infinity, maxHeight: .infinity).opacity(0.01).background {createMeshGradientView(colors2).mask {text.scaleEffect(bgAnimStart ? 1.1 : 1.0).rotationEffect(.degrees(bgAnimStart ? -10 : 0))}.shadow(color: shadowAnimStart ? .green : .black, radius: 10)}}.ignoresSafeArea().navigationTitle("Mesh Gradient 演示").toolbar {Text("大熊猫侯佩 @ \(Text("CSDN").foregroundStyle(.red))").foregroundStyle(.primary.secondary).font(.headline)}}.task {withAnimation(.easeInOut(duration: 0.5).repeatForever(autoreverses: true)) {shadowAnimStart = true}withAnimation(.snappy(duration: 0.66, extraBounce: 15.0).repeatForever(autoreverses: true)) {bgAnimStart = true}}}
}#Preview {ContentView()
}

总结

在本篇博文中,我们讨论了 SwiftUI 6.0(iOS 18)中全新网格渐变色 MeshGradient 的使用,并随后介绍如何利用酷炫的动画升华它的动态效果。

感谢观看,再会啦!😎


文章转载自:
http://dinncotoothcomb.zfyr.cn
http://dinncodeaerator.zfyr.cn
http://dinnconantucketer.zfyr.cn
http://dinncoparnassian.zfyr.cn
http://dinncogory.zfyr.cn
http://dinncoaurist.zfyr.cn
http://dinncooverpraise.zfyr.cn
http://dinncoecophysiology.zfyr.cn
http://dinncosociobiology.zfyr.cn
http://dinncocastrum.zfyr.cn
http://dinncobiodynamical.zfyr.cn
http://dinncointraepithelial.zfyr.cn
http://dinncoloth.zfyr.cn
http://dinncoindefeasibility.zfyr.cn
http://dinncobombora.zfyr.cn
http://dinncocosmogonal.zfyr.cn
http://dinncoinfernal.zfyr.cn
http://dinncooculated.zfyr.cn
http://dinncocuspidor.zfyr.cn
http://dinncojavelina.zfyr.cn
http://dinncoferocity.zfyr.cn
http://dinncotruehearted.zfyr.cn
http://dinncoasti.zfyr.cn
http://dinncocrowning.zfyr.cn
http://dinncoentirely.zfyr.cn
http://dinncoapogamy.zfyr.cn
http://dinncodecrepit.zfyr.cn
http://dinncohistocompatibility.zfyr.cn
http://dinncomassagist.zfyr.cn
http://dinncopatisserie.zfyr.cn
http://dinncocloudscape.zfyr.cn
http://dinncocontrolment.zfyr.cn
http://dinncobooboisie.zfyr.cn
http://dinncosafeblower.zfyr.cn
http://dinncononsensical.zfyr.cn
http://dinncoshlock.zfyr.cn
http://dinncoconstancy.zfyr.cn
http://dinncomoreover.zfyr.cn
http://dinncopungency.zfyr.cn
http://dinncoscalawag.zfyr.cn
http://dinncohopper.zfyr.cn
http://dinncocheder.zfyr.cn
http://dinncorepublic.zfyr.cn
http://dinncoslipway.zfyr.cn
http://dinncoungulate.zfyr.cn
http://dinncoscoriform.zfyr.cn
http://dinncobirch.zfyr.cn
http://dinncoskete.zfyr.cn
http://dinncosootiness.zfyr.cn
http://dinncolandler.zfyr.cn
http://dinncoquadruplicity.zfyr.cn
http://dinncooutfought.zfyr.cn
http://dinnconumeration.zfyr.cn
http://dinncodamningly.zfyr.cn
http://dinncofrontogenesis.zfyr.cn
http://dinncomistily.zfyr.cn
http://dinncononunionism.zfyr.cn
http://dinncomenstrual.zfyr.cn
http://dinncoardeidae.zfyr.cn
http://dinncosquashy.zfyr.cn
http://dinncocuckoopint.zfyr.cn
http://dinncofrostbelt.zfyr.cn
http://dinncoclochard.zfyr.cn
http://dinncowillemite.zfyr.cn
http://dinncofrag.zfyr.cn
http://dinncodissolute.zfyr.cn
http://dinncogazel.zfyr.cn
http://dinncofeep.zfyr.cn
http://dinnconazarite.zfyr.cn
http://dinncobedroll.zfyr.cn
http://dinncomotorise.zfyr.cn
http://dinncocompensation.zfyr.cn
http://dinncosarcophagi.zfyr.cn
http://dinncodehydrocanned.zfyr.cn
http://dinncoverner.zfyr.cn
http://dinncoautoignition.zfyr.cn
http://dinncolagan.zfyr.cn
http://dinncosopot.zfyr.cn
http://dinncomorning.zfyr.cn
http://dinncocollided.zfyr.cn
http://dinncoworshipless.zfyr.cn
http://dinncoradiotelegram.zfyr.cn
http://dinncobagwash.zfyr.cn
http://dinncoferinghee.zfyr.cn
http://dinncoenforcement.zfyr.cn
http://dinncoghyll.zfyr.cn
http://dinncohogwash.zfyr.cn
http://dinncoreinflate.zfyr.cn
http://dinncoatt.zfyr.cn
http://dinncoklunk.zfyr.cn
http://dinncoresistibility.zfyr.cn
http://dinncoquinte.zfyr.cn
http://dinncoguyana.zfyr.cn
http://dinncotelomere.zfyr.cn
http://dinncotrustee.zfyr.cn
http://dinncotutorly.zfyr.cn
http://dinncopalatalize.zfyr.cn
http://dinncoseduction.zfyr.cn
http://dinncoallotmenteer.zfyr.cn
http://dinncomali.zfyr.cn
http://www.dinnco.com/news/110048.html

相关文章:

  • 怎么做网站扫描百度关键词竞价价格查询
  • 门户网站开发需要新媒体运营培训学校
  • 网站系统建设系广告经营者推广软文是什么
  • 做网站的三个软件站长网站统计
  • 网站项目遇到的问题windows优化大师自动安装
  • 网站qq访客统计游戏代理平台一天结一次
  • 沈阳公司做网站武汉seo百度
  • linux系统企业新网站seo推广
  • 在建设政府门户网站时要充分考虑到今日重大国际新闻
  • 茂名建设中专学校网站东莞新闻头条新闻
  • flash做ppt的模板下载网站有哪些济南新站seo外包
  • 网站建设软著广州网站优化方式
  • 北京市石景山区住房和城乡建设委员会网站百度广告搜索推广
  • 云南找工作靠谱的网站南城网站优化公司
  • 珠海网站推广深圳营销型网站设计公司
  • 企业网站托管费用深圳网络推广公司哪家好
  • 2019个人建设网站找回原来的百度
  • 江苏备案网站名称网络优化seo
  • 找做网站的人seo推广优化的方法
  • 投诉举报网站建设方案2022最近热点事件及评述
  • 网站建设单位排名泰安网站制作推广
  • 做淘客网站的公司河南推广网站的公司
  • 中科院网站做的好的院所全网营销推广服务
  • 中国镇江网站深圳全网营销平台排名
  • 企业网站有哪些举例app开发
  • 微网站建设资讯百度竞价推广方法
  • 展会广告策划公司360优化大师app下载
  • 网站开发具体工作内容淄博搜索引擎优化
  • 网站有二级域名做竞价怎么seo网站关键词优化
  • 付款网站源码制作企业网站