swiftui 轨迹_SwiftUI 动画控制运行轨迹之Curve(2020教程)

本文价值与收获

看完本文后,您将能够作出下面的动画

看完本文您将掌握的技能掌握4种内置动画曲线使用

实现移动

实现颜色变换

欣赏远古壁画

QQ:3365059189 SwiftUI技术交流QQ群:518696470

动画曲线是一种在整个动画过程中表达速度的方式。在前面的示例中,您看到了“ easeInOut”效果。目前苹果内置了四个运动曲线 - easeInout - default - easeIn - easeOut

Curve 例子

为了显示效果,我们通过下面等例子来体验一下

1、 做个照片struct,方便配置效果

struct ImageBox: View {

@State var name = "1"

var body:some View {

Image(name)

.resizable()

.aspectRatio(contentMode: .fit)

.frame(width:100)

.cornerRadius(10)

.shadow(color: .white, radius: 10, x: 0, y: 0)

.padding()

}

}

2、 配置图片移动动画

GeometryReader { gr in

ImageBox(name: "1")

.position(x: self.move ? (gr.size.width - 40) : 40, y: 40)

.animation(.easeInOut(duration: 2))

}

3、完整效果

import SwiftUI

struct ImageBox: View {

@State var name = "1"

var body:some View {

Image(name)

.resizable()

.aspectRatio(contentMode: .fit)

.frame(width:100)

.cornerRadius(10)

.shadow(color: .white, radius: 10, x: 0, y: 0)

.padding()

}

}

struct CurveView: View {

@State private var move = false

var body: some View {

VStack{

Text("QQ:3365059189")

.padding()

Text(" SwiftUI技术交流QQ群:518696470 ")

.font(.largeTitle)

.padding()

.foregroundColor(.white)

.background(self.move ? Color.orange : Color.purple)

.cornerRadius(10)

.shadow(color: .white, radius: 4, x: 0, y: 0)

.animation(.easeInOut(duration: 2))

// Spacer()

Group{

GeometryReader { gr in

ImageBox(name: "1")

.position(x: self.move ? (gr.size.width - 40) : 40, y: 40)

.animation(.easeInOut(duration: 2))

}

Text("easeInOut: 慢,快,慢")

.font(.title)

.foregroundColor(.white)

GeometryReader { gr in

ImageBox(name: "2")

.position(x: self.move ? (gr.size.width - 40) : 40, y: 40)

.animation(.easeIn(duration: 2))

}

Text("easeIn: 慢")

.font(.title)

.foregroundColor(.white)

GeometryReader { gr in

ImageBox(name: "3")

.position(x: self.move ? (gr.size.width - 40) : 40, y: 40)

.animation(.easeOut(duration: 2))

}

Text("easeOut: 快")

.font(.title)

.foregroundColor(.white)

GeometryReader { gr in

ImageBox(name: "4")

.position(x: self.move ? (gr.size.width - 40) : 40, y: 40)

.animation(.linear(duration: 2))

}

Text("easeIn: 匀速")

.font(.title)

.foregroundColor(.white)

//ImageBox(name: "2")

//ImageBox(name: "3")

//ImageBox(name: "4")

}

// group end

Spacer()

Button(action:{

self.move.toggle()

//print("here")

}) {

Text(" 启动 ")

.font(.title)

.foregroundColor(.white)

.padding()

.background(Color.orange)

.cornerRadius(20)

.shadow(radius: 10)

}.padding()

}.background(

Image("3yue")

.resizable()

.aspectRatio(contentMode: .fill)

.edgesIgnoringSafeArea(.all)

)

}

}

如需源码可以加入我QQ

QQ:3365059189 SwiftUI技术交流QQ群:518696470

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【课程特点】1、231节大容量课程:包含了SwiftUI的大部分知识点,详细讲解SwiftUI的方方面面;2、15个超级精彩的实例:包含美食、理财、健身、教育、电子商务等各行业的App实例;3、创新的教学模式:手把手教您SwiftUI用户界面开发技术,一看就懂,一学就会;4、贴心的操作提示:让您的眼睛始终处于操作的焦点位置,不用再满屏找光标;5、语言简洁精练:瞄准问题的核心所在,减少对思维的干扰,并节省您宝贵的时间;6、视频短小精悍:即方便于您的学习和记忆,也方便日后对功能的检索;7、齐全的学习资料:提供所有课程的源码,在Xcode 11 + iOS 13环境下测试通过; 更好的应用,更少的代码!SwiftUI是苹果主推的下一代用户界面搭建技术,具有声明式语法、实时生成界面预览等特性,可以为苹果手机、苹果平板、苹果电脑、苹果电视、苹果手表五个平台搭建统一的用户界面。SwiftUI是一种创新、简单的iOS开发中的界面布局方案,可以通过Swift语言的强大功能,在所有的Apple平台上快速构建用户界面。 仅使用一组工具和API为任何Apple设备构建用户界面。SwiftUI具有易于阅读和自然编写的声明式Swift语法,可与新的Xcode设计工具无缝协作,使您的代码和设计**同步。自动支持动态类型、暗黑模式、本地化和可访问性,意味着您的**行SwiftUI代码已经是您编写过的非常强大的UI代码了。 
SwiftUI is a new framework introduced by Apple in 2019 for building user interfaces on all Apple platforms (iOS, iPadOS, macOS, watchOS, and tvOS). It provides a new way of declaratively building user interfaces using Swift code. Objective-C, on the other hand, is an object-oriented programming language that has been widely used for building Mac and iOS applications. It has been around for much longer than SwiftUI, and has a large and established developer community. Here are some key differences between the two: 1. Syntax: SwiftUI has a simpler and more intuitive syntax compared to Objective-C, which can be more verbose and difficult to read. 2. Declarative vs Imperative: SwiftUI is a declarative framework, which means you describe what your user interface should look like, and the framework takes care of rendering it on the screen. Objective-C, on the other hand, is an imperative language, which requires you to write code to manipulate the user interface elements directly. 3. Interoperability: SwiftUI and Objective-C can coexist in the same project, and it is possible to use SwiftUI components in Objective-C code. However, the reverse is not true, as Objective-C code cannot be used in SwiftUI. 4. Learning Curve: SwiftUI is generally considered easier to learn for new developers, whereas Objective-C has a steeper learning curve. Ultimately, the choice between SwiftUI and Objective-C depends on the specific needs and preferences of each developer and the project they are working on. Both frameworks have their strengths and weaknesses, and both can be used to build high-quality and performant applications.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值