User Experience and Animations in SwiftUI app | Todo List #5

Swiftful Thinking
18 Mar 202122:31

Summary

TLDR在这段视频中,Nick 带领观众构建了一个 Swift UI 待办事项应用程序,并专注于提升用户体验。当待办事项列表为空时,屏幕显得过于空白,Nick 通过添加一条消息来告知用户列表为空,并鼓励他们添加新项目。此外,他还为应用程序添加了动画效果,使界面看起来更加酷炫。Nick 展示了如何在 Xcode 中创建一个新的 SwiftUI 视图,称为“无项目视图”,并详细说明了如何使用滚动视图、文本、导航链接和按钮来设计这个视图。他还介绍了如何利用状态变量和 `.onAppear` 修饰符来实现动画效果,包括颜色变化、按钮大小变化以及阴影效果。最后,Nick 还介绍了如何自定义应用程序的强调颜色,并将其应用到整个应用程序中,以保持界面的一致性和美观性。

Takeaways

  • 📝 在Swift UI中创建一个待办事项列表应用,并关注用户体验。
  • 🎨 当待办事项列表为空时,添加一个提示信息,告知用户并提供添加新项的选项。
  • 🔄 通过动画效果提升应用的视觉效果,使应用看起来更加酷炫。
  • 🗑️ 使用UserDefaults保存应用中的项目,并在列表为空时展示一个友好的提示。
  • 📱 即使列表为空,也要保持导航标题和栏项在屏幕上显示。
  • 📖 创建一个新的Swift UI视图,名为“NoItemsView”,用于展示当待办事项列表为空时的界面。
  • 🔍 通过ScrollView实现内容的滚动,确保内容始终位于屏幕顶部。
  • 🎭 使用ZStack和条件语句来决定是展示列表还是“NoItemsView”。
  • 🔗 通过NavigationView和NavigationLink在应用内部导航。
  • 🎉 添加一个引人注目的按钮,鼓励用户点击以添加待办事项。
  • 🌟 使用动画和交互效果,如按钮的缩放、阴影和颜色变化,增强用户界面的动态感。
  • 🖌️ 通过Assets.xcassets自定义应用的Accent Color,以符合设计主题。

Q & A

  • 在SwiftUI中,为什么要在空的待办事项列表上添加消息?

    -在SwiftUI中,当待办事项列表为空时,添加消息可以提供更好的用户体验。它告知用户列表是空的,并非应用加载不完整或出现错误,同时给予用户添加新项的选项。

  • 如何使用SwiftUI的ZStack来显示空列表消息?

    -通过在ZStack中添加条件逻辑,如果`listViewModel.items`数组为空,则显示一个文本视图,上面写着“没有项目”,否则显示已剪切的列表。

  • 在SwiftUI中,如何创建一个当待办事项列表为空时显示的自定义视图?

    -创建一个新的SwiftUI视图文件,命名为`noItemsView`。在这个视图中,使用ScrollView和VStack来布局标题、描述文本和一个按钮,并通过设置字体、颜色和对齐方式来美化这个视图。

  • 如何让待办事项列表在没有项目时显示一个提示信息,并添加一些动画效果?

    -使用`@State`变量`animate`来控制动画的显示,并在`onAppear`修饰符中调用`addAnimation`函数,该函数使用`withAnimation`来改变`animate`变量的值,并添加延迟和动画效果。

  • 在SwiftUI中,如何实现按钮的动画效果,使其看起来像是在弹跳?

    -通过在`NavigationLink`上使用`.padding()`、`.scaleEffect()`和`.offset()`修饰符,以及在`.shadow()`中设置动画,可以使按钮在用户交互时产生弹跳和阴影变化的效果。

  • 如何改变SwiftUI应用中的全局强调颜色(Accent Color)?

    -在Xcode的Assets文件夹中找到并选择Accent Color,然后使用颜色面板来自定义颜色。此外,可以创建一个新的颜色集,比如命名为Secondary Accent Color,并在需要的地方使用这个新颜色。

  • 在SwiftUI中,如何将自定义视图嵌入到应用的其他部分?

    -在需要显示该视图的地方,比如`ListView`中,使用条件语句来决定是显示待办事项列表还是显示自定义的`NoItemsView`。

  • 为什么需要在显示空列表消息时保持导航标题和栏项在屏幕上?

    -保持导航标题和栏项在屏幕上有助于维持应用的导航结构和用户对应用布局的预期,即使在没有数据展示的情况下也能让用户了解他们当前在应用中的位置。

  • 在SwiftUI中,如何避免动画效果重复执行?

    -通过在执行动画代码之前添加一个检查,确保`animate`变量为`false`。如果`animate`为`true`,则不执行动画代码,这样可以避免在用户返回到该视图时动画重复执行。

  • 在SwiftUI中,如何为新创建的空列表视图添加导航链接按钮?

    -使用`NavigationLink`组件,并设置其`destination`为待添加项的视图(如`AddView`),同时为按钮设置一个吸引人的标签和可能的emoji符号,以鼓励用户进行交互。

  • 如何让SwiftUI中的列表在删除所有项后显示自定义的空列表视图?

    -在列表视图的代码中,使用一个条件语句检查列表是否有项。如果没有项,则展示`NoItemsView`视图;如果有项,则展示列表本身。

  • 在SwiftUI中,如何为视图添加淡入效果的过渡动画?

    -在视图的声明中使用`.transition(.opacity)`修饰符,并为其设置动画效果,如`.animation(.easeIn)`,以实现淡入效果的过渡动画。

Outlines

00:00

🎨 提升用户体验:为空白待办事项列表添加提示信息

Nick在视频中介绍了如何改善待办事项应用的用户体验。当待办事项列表为空时,界面看起来非常空白,这可能会让用户误以为应用没有正确加载。为了解决这个问题,他提出在屏幕上添加一条消息,告知用户列表为空,并提供一个添加新项目的选项。此外,他还计划添加一些动画效果,使应用看起来更加酷炫。

05:01

📝 创建无项目视图:引导用户添加任务

为了在待办事项列表为空时给用户更好的指引,Nick创建了一个名为'no items view'的新视图。这个视图包括一个滚动视图、一个标题和一个描述,鼓励用户点击添加按钮来添加任务。此外,还有一个导航链接按钮,使用户能够方便地跳转到添加任务的界面。

10:01

🔄 添加动画效果:提升应用互动性

为了让应用看起来更加生动,Nick在'no items view'中添加了动画效果。他首先创建了一个状态变量'animate',并在视图出现的'onAppear'事件中设置了延迟和动画逻辑。动画包括改变按钮背景颜色、按钮大小、阴影以及按钮的上下移动,以模拟按钮的悬浮效果。

15:06

🖌️ 自定义颜色:设置应用的主题颜色

Nick展示了如何自定义应用的颜色主题。他通过Xcode的资产编辑器更改了应用的强调颜色(accent color)为深紫色,并创建了一个新的颜色集作为次要强调颜色(secondary accent color),用于按钮动画的颜色变化。

20:09

📱 集成无项目视图:完成应用功能

最后,Nick将新创建的'no items view'集成到了应用的其余部分。他确保当列表为空时,展示这个新视图,并添加了透明度渐变的过渡效果,使得视图在出现时有一个平滑的动画过渡。通过在模拟器上测试,确认了动画效果和导航功能按预期工作。

Mindmap

Keywords

💡Swift UI

Swift UI是一个由苹果公司开发的用户界面设计框架,用于创建iOS、macOS、watchOS和tvOS应用程序的原生用户界面。在视频中,Nick使用Swift UI来构建一个待办事项列表应用程序,展示了如何利用Swift UI的组件和功能来设计和实现用户界面。

💡用户体验 (User Experience)

用户体验指的是用户在使用产品或服务过程中的感受和反应。在视频中,Nick关注于改善待办事项列表应用的用户体验,特别是在列表为空时,通过添加提示信息和动画来避免用户面对空白屏幕的困惑。

💡UserDefaults

UserDefaults是iOS中的一个API,用于存储应用程序的用户偏好设置。在视频中,Nick提到使用UserDefaults来保存待办事项列表中的项目,这样即使应用程序关闭,用户的数据也不会丢失。

💡Z-Stack

Z-Stack是Swift UI中的一个布局组件,用于在Z轴上堆叠元素,从而创建层叠效果。在视频中,Nick使用Z-Stack来决定在待办事项列表为空时显示提示信息,或者当有项目时显示列表。

💡NavigationView

NavigationView是Swift UI中的一个组件,用于提供导航功能,允许用户通过堆栈导航返回到前一个屏幕。在视频中,Nick在创建“无项目视图”时,提到了NavigationView,以确保即使在显示不同的视图时,导航栏和标题仍然可见。

💡V-Stack

V-Stack是Swift UI中的一个布局组件,用于垂直堆叠元素。在视频中,Nick使用V-Stack来组织“无项目视图”中的标题、描述和按钮,使它们在界面上垂直排列。

💡Navigation Link

Navigation Link是Swift UI中的一个组件,允许用户点击以导航到另一个视图。在视频中,Nick使用Navigation Link创建了一个按钮,当用户点击时,可以导航到添加新待办事项的视图。

💡动画 (Animation)

在Swift UI中,动画是用于在用户界面元素变化时添加视觉效果的一种技术。视频中,Nick为“无项目视图”中的按钮添加了动画效果,包括颜色变化、阴影变化和大小变化,以吸引用户的注意力并提高应用的交互性。

💡状态变量 (State Variable)

状态变量在Swift UI中用于存储随时间变化的值,并且可以在UI中被观察以触发响应的变化。在视频中,Nick使用了一个名为`animate`的状态变量来控制按钮动画的显示和隐藏。

💡Accent Color

Accent Color是Swift UI中用于定义应用程序中主要颜色的主题颜色。在视频中,Nick自定义了应用程序的Accent Color,将其从默认的蓝色更改为紫色,并添加了一个次要的Accent Color用于动画效果。

💡Transition

Transition是Swift UI中的一个属性,用于定义视图出现和消失时的动画效果。在视频的最后,Nick为“无项目视图”添加了一个透明度渐变的Transition,以增强视图切换时的视觉效果。

Highlights

在Swift UI中创建待办事项列表应用,专注于提升用户体验。

当待办事项列表为空时,屏幕上显示空白,给用户不佳的体验。

通过添加消息提示用户列表为空,并提供添加新项的选项。

为提升视觉效果,添加了动画效果。

使用UserDefaults保存应用中的项目。

在Xcode中,通过条件逻辑判断列表是否为空来展示不同的视图。

创建一个简单的视图,当待办事项列表为空时显示。

即使列表为空,也保持导航标题和栏项在屏幕上显示。

使用ZStack来根据列表是否为空显示不同的视图。

创建了一个新的Swift UI视图文件,命名为NoItemsView。

在NoItemsView中添加了滚动视图和VStack来布局文本和按钮。

为NoItemsView添加了导航标题和按钮,鼓励用户添加新事项。

使用了NavigationLink来实现在点击按钮时导航到添加视图。

为按钮添加了动画效果,包括颜色变化、缩放和阴影变化。

通过修改Assets.xcassets中的AccentColor来自定义应用的颜色主题。

创建了次要强调颜色(Secondary Accent Color)用于动画效果。

将NoItemsView整合到应用中,并在列表为空时显示。

为NoItemsView添加了透明度动画,使其平滑地出现在屏幕上。

Transcripts

play00:01

[Music]

play00:06

what's up everyone

play00:07

i'm nick this is swiffle thinking and in

play00:10

this playlist we are building a swift ui

play00:12

to-do list

play00:13

app and in this video we're going to

play00:15

focus a little bit on

play00:16

user experience because right now when

play00:19

our list is

play00:20

empty the screen looks really really

play00:22

blank

play00:23

and that's not a good user experience so

play00:25

instead we're going to add a little

play00:27

message on the screen

play00:28

telling our users that there are no

play00:30

items on the list giving them an option

play00:32

to add new items and we're going to add

play00:34

a little bit of animation

play00:36

just to make it look really really cool

play00:39

all right so we are back in xcode of

play00:42

course

play00:43

and in the last video in the series we

play00:45

actually put together

play00:46

some logic to save the items in our app

play00:50

so now all of our items are being saved

play00:52

in user defaults

play00:54

but you might have noticed in the last

play00:56

video when we first

play00:57

ran our app while it was using the user

play01:00

defaults

play01:01

at the at the launch of the app we had

play01:03

no items in our list

play01:05

and it looked a little bit like this if

play01:08

i delete these items

play01:10

our list is completely empty so it's

play01:13

correct to not show any items

play01:16

but if this was an app and we had like a

play01:18

user using our app

play01:19

they might see this screen and think

play01:21

that it didn't finish loading

play01:23

because it looks very blank here we're

play01:25

not really sure if

play01:26

the app is just not working correctly or

play01:29

is our list

play01:29

actually empty so what i want to do is

play01:32

put a little notification

play01:34

a little text here just saying that the

play01:37

to-do list is

play01:38

empty just to signal to the user that

play01:41

this is the list this is the screen

play01:43

but there are no items right now so

play01:46

we're just going to create a very simple

play01:47

view to put right here when the to-do

play01:49

list is empty

play01:51

so we're not going to need the simulator

play01:52

so i'm going to just press stop

play01:55

and close out of the simulator because

play01:57

the simulator does slow down your

play01:59

computer a little bit it does cause the

play02:00

fan to go on because it's

play02:01

a lot of computing power so i try to

play02:04

close it whenever possible

play02:06

and in our project here i'm going to

play02:08

open up

play02:09

the canvas

play02:12

and if you click resume on the canvas it

play02:14

should build

play02:15

with an empty list and that's because

play02:18

we're using our new

play02:19

list view model and in the preview we

play02:21

don't have anything saved in the user

play02:23

defaults

play02:24

and what i want to do is add some logic

play02:26

so that

play02:27

if this list if there are no items in

play02:30

this list

play02:30

we show that the new view that we're

play02:32

about to create instead of

play02:34

this list but regardless of whether we

play02:37

show a list or this new view

play02:39

i want to always keep this navigation

play02:40

title and the bar items on the screen

play02:43

so even if we don't have this list i

play02:44

still want to keep this

play02:46

and what i'm going to do is add a

play02:48

z-stack first

play02:50

open the brackets i'm going to cut the

play02:52

list in the list style

play02:58

and in this z stack we're going to add

play02:59

some logic we're going to say if

play03:02

list view model dot

play03:05

items which is the items array dot is

play03:07

empty

play03:08

so if it is empty and there are no items

play03:10

open the brackets

play03:12

and here we're going to add a text and

play03:14

we'll just write

play03:15

no items and then we'll say

play03:18

else so if it is not empty and there is

play03:21

items we're going to paste in the list

play03:23

that we just cut

play03:24

here so the list is only going to be

play03:26

shown if there are items and then if

play03:28

there are no items right now we're just

play03:29

going to show this

play03:30

text but regardless of whether we're

play03:33

showing this text

play03:34

or the list this navigation title and

play03:36

the bar items will always be on the

play03:38

screen

play03:38

so now that we have this we can see the

play03:40

no items is showing but of course

play03:42

we want to customize this to make it

play03:44

look better than just saying no items

play03:46

so let's create a new file to do this

play03:48

i'm going to open up the navigator

play03:50

i'm going to right click somewhere in

play03:51

the views folder create a new file

play03:54

it's going to be a swift ui view and

play03:56

let's call this

play03:57

no items view

play04:01

go ahead and click create once you're

play04:03

inside click resume on the canvas

play04:06

and i'm going to hide the navigator

play04:08

because we're not going to use it for a

play04:09

while

play04:11

all right now this view is going to be

play04:13

fairly simple we're going to get started

play04:14

by adding a scroll view

play04:17

to the screen open the brackets and if

play04:20

we add some text in here we can see that

play04:22

it goes all the way to the top of the

play04:24

screen and part of the reason i'm adding

play04:26

the scroll view if we click on it you

play04:28

can see that it does

play04:29

have a max height of infinity it extends

play04:31

as big as possible

play04:33

and also it formats the content to be

play04:35

all the way at the top

play04:36

and it's just handy because if we just

play04:38

had text here it would be right in the

play04:40

center of the screen

play04:41

and i want this content to be pushed to

play04:43

the top so i'm going to do a scroll view

play04:45

and while we're here

play04:46

let's just make it as big as possible

play04:48

just in case

play04:50

just in case our content isn't for some

play04:52

reason the full width of the screen

play04:54

so on the scroll view we'll just add dot

play04:56

frame

play04:57

i'm going to use the min max completion

play05:00

and we only need the max width

play05:04

of infinity and the max height

play05:08

of infinity and you could have typed

play05:10

that in directly we don't need the

play05:11

alignment

play05:12

you could have typed this in uh

play05:14

sometimes i just like using the

play05:15

completions

play05:16

and one other thing i want to note is

play05:18

that when we are showing this no items

play05:20

view

play05:20

so when we're in this list view we have

play05:22

the no items here

play05:24

uh we are in a navigation view so we

play05:26

have a navigation title on this screen

play05:28

so if i go back into our no items view

play05:31

we

play05:32

we are actually going to be in a

play05:33

navigation view so let's add that quick

play05:35

to the preview we'll add a navigation

play05:37

view open the brackets

play05:40

paste this inside and let's just add a

play05:43

navigation title

play05:44

just say title for now and just so we

play05:46

know what it looks like when it's going

play05:47

to be on the actual screen so our scroll

play05:49

view starts down here now

play05:52

and in the scroll view let's add a v

play05:54

stack open the brackets

play05:57

let's add a text this will be the title

play05:59

that says uh there are

play06:00

no items you can put whatever you want

play06:03

in this title

play06:04

let's make it dot font of title let's

play06:07

give it a font

play06:08

weight of semi-bold semi-bold always

play06:11

looks good

play06:12

below this text let's add a description

play06:14

we'll do another text

play06:15

and we're going to say are you a

play06:18

productive person

play06:23

i think you should click the add

play06:26

button and add a bunch of items

play06:32

to your to-do list and on the

play06:35

entire v stack let's give it a dot

play06:38

multi-line text alignment of center so

play06:42

it's center aligned and

play06:43

on this v stack let's add maybe some

play06:45

spacing

play06:46

of 10 and on the entire

play06:50

v stack right below this multi-line

play06:52

alignment let's just add some padding

play06:54

to push it all in of maybe 40.

play06:58

i think that looks good so we have our

play07:00

screen mostly complete

play07:02

and now all i want to do is put a button

play07:04

below this so in addition to the add

play07:05

button that we have on the top right of

play07:07

the screen

play07:08

i also want to add a big button here to

play07:10

get people to actually click on it to go

play07:11

to our ad view

play07:13

so when we click this this button is

play07:15

actually going to be a navigation

play07:16

link because we want to navigate within

play07:19

our navigation view we're going to push

play07:20

to the add view so we'll add a

play07:22

navigation

play07:23

link open the parentheses we're going to

play07:26

use the destination and

play07:28

label completion destination will be our

play07:30

ad view which we made a couple videos

play07:32

back

play07:33

and our label instead of just saying

play07:36

navigate

play07:37

let's click resume so that we know we

play07:39

that it builds

play07:41

our label instead of saying navigate

play07:42

let's say add something

play07:45

and then i'm going to press ctrl command

play07:47

space to bring up the

play07:48

emoji keyboard and maybe use the party

play07:51

face because everybody loves the party

play07:53

face

play07:54

let's give this some formatting so let's

play07:56

do maybe

play07:57

dot foreground color of white

play08:01

dot font of headline

play08:04

let's give it a background color of

play08:06

color dot accent

play08:07

color and we're gonna update this accent

play08:09

color in a second by default it is blue

play08:11

that's the blue that you see like across

play08:13

the whole app when we create buttons

play08:15

we're going to update it in a second

play08:16

actually

play08:17

but before this background let's add a

play08:20

dot frame

play08:21

with a height of 55 and a dot frame with

play08:25

a max width

play08:26

of infinity after the background let's

play08:30

add a dot corner radius of 10

play08:33

now our button looks pretty good now we

play08:36

could just leave this this looks pretty

play08:37

good

play08:38

but i want to add a little bit of

play08:40

animation just because animations always

play08:42

make

play08:42

your app look a little bit better and it

play08:44

would be good practice to just

play08:45

run through some basic animations so at

play08:48

the top of this view

play08:49

let's create an at state var let's call

play08:52

it animate

play08:54

of type bool and we'll set it equal to

play08:56

false

play08:59

we want to animate when this appears on

play09:01

the screen so at the bottom of the

play09:04

v stack maybe underneath the padding

play09:06

here let's add

play09:08

on up here open the brackets

play09:11

and in this on appear call we're going

play09:12

to add some animation

play09:14

so there's going to be a little bit of

play09:15

logic in our animation call so i'm going

play09:17

to actually create a

play09:18

function down here underneath the body

play09:21

so you can

play09:22

double click on the open brackets in the

play09:24

body you'll find the end of it

play09:27

and underneath the body we're gonna add

play09:29

a funk

play09:30

add animation open and close the

play09:33

parentheses

play09:34

open the brackets and we're going to

play09:36

call this from

play09:37

our on appear call and i actually want

play09:39

to use the perform completion

play09:41

i clicked the wrong one before let's uh

play09:44

call dot on appear

play09:46

and go to the perform completion and

play09:49

then we're going to get

play09:50

rid of these brackets here and the

play09:53

function we're going to call

play09:54

is add animation let's get rid of this

play09:56

one here

play09:57

so ever nice and clean on up here it's

play10:00

calling add animation

play10:02

and this is our function and when the

play10:04

screen appears

play10:06

i want to delay one second before the

play10:08

animation starts

play10:09

so let's add a delay first we'll call

play10:11

dispatch q

play10:12

dot main dot async after

play10:16

the deadline will be dot now plus

play10:19

let's do 1.5 for 1.5 seconds

play10:23

then in the execute i'm going to hit

play10:24

enter and we can put our animation code

play10:27

here so to cause the animation we are

play10:30

going to of course

play10:30

toggle the animate boolean and we want

play10:33

to do it with animation so we'll call

play10:35

with animation

play10:37

dot ease in out which is a nice one

play10:40

then we'll open the brackets and in here

play10:42

we'll call animate

play10:44

dot toggle so

play10:47

when this appears it's going to add

play10:48

animation and the add animation is going

play10:51

to wait 1.5 seconds and then

play10:53

toggle one thing i want to note quickly

play10:56

is that

play10:57

the on appear gets called every time the

play10:59

screen appears

play11:00

so in our app if a user had opened open

play11:03

our main screen of our app

play11:04

press the add button to go to the second

play11:06

screen and then press the back button to

play11:08

go back to this screen

play11:10

the on appear would get called when they

play11:13

first loaded the app

play11:14

and then again when they press the back

play11:15

button to come back to this screen

play11:17

because the on appear gets called every

play11:19

time this screen appears

play11:21

and while that's good i don't want to

play11:24

add the animation twice

play11:25

because if we already have the animation

play11:26

running we don't want to toggle it again

play11:29

so just in case that ever were to happen

play11:31

we're going to add a quick little check

play11:33

here we're going to make sure

play11:34

that this animate boolean is false

play11:38

because if it's true then it's already

play11:40

animating so before we call the dispatch

play11:43

queue let's just call

play11:44

guard not animate else

play11:47

return so we're gonna say guard make

play11:51

sure

play11:52

animate is not true so animate is false

play11:56

otherwise return because if animate is

play11:58

true we're just going to return out of

play11:59

the function and we're not going to go

play12:00

through with this

play12:02

so we're making sure we don't call it

play12:03

twice and now let's add a little bit of

play12:06

animation

play12:07

so the first thing we're going to do is

play12:08

the background and i'm going to

play12:11

close the navigator and maybe zoom out a

play12:13

little bit

play12:14

just so we can put more code on the

play12:16

screen

play12:18

the background color right now is

play12:19

color.accent color but let's make it

play12:21

uh if it's animate we're gonna use a

play12:23

ternary operator question mark

play12:26

and we'll do color dot red otherwise

play12:28

let's do color dot accent color

play12:31

so if i click resume on the canvas and i

play12:34

press the play in the live preview

play12:36

it should now animate from blue to red

play12:40

awesome and that was good but we can do

play12:43

a little bit better i don't want to just

play12:44

go from blue to red i wanted to keep

play12:46

going from blue to red

play12:48

so let's customize the animation so

play12:50

instead of just ease in

play12:52

out i'm going to delete this and i'm

play12:54

going to press

play12:55

enter make these on separate lines and

play12:57

let's add a custom animation we'll call

play12:59

animation capital a no add modifiers to

play13:03

the animation we'll call dot

play13:05

ease in out but this time let's use the

play13:08

duration so we can make it a little bit

play13:10

longer than it normally is so we'll call

play13:12

2.0 for two seconds

play13:14

and then we'll call dot repeat forever

play13:18

and now if we click play on the live

play13:20

preview it should

play13:22

go from blue to red with a duration of

play13:24

two seconds and it should repeat forever

play13:27

and this is looking a little better

play13:28

already but i think we can make it even

play13:31

better

play13:32

so on this navigation link on the whole

play13:34

navigation link let's add some padding

play13:37

let's use the edges and we'll do dot

play13:39

horizontal

play13:40

and then maybe let's see what it looks

play13:42

like with 30.

play13:44

so it's a little looks a little smaller

play13:45

when it's 30 here and what about 50

play13:49

and that's even smaller so let's animate

play13:50

between those two we'll call

play13:52

animate question mark

play13:56

if it's animate we'll do 30 otherwise

play13:59

50.

play14:00

and now our button looks like it's kind

play14:01

of getting bigger and smaller

play14:03

or a little bit wider just because we're

play14:05

animating the padding on the outside of

play14:08

the button let's also give it a little

play14:11

bit of a scale effect we'll call dot

play14:12

scale effect

play14:14

go down to the cg float option and we'll

play14:15

do animate

play14:17

if it's animate let's do 1.1 times the

play14:20

the current size

play14:21

otherwise we'll do 1.0 so just the

play14:23

current size

play14:25

so now it should get looks like it gets

play14:27

a little bit bigger

play14:28

and then a little bit smaller let's also

play14:31

animate the offset so it looks like it's

play14:33

moving up and down a little so we'll do

play14:34

dot offset

play14:36

and we're not going to use the x so

play14:37

we'll delete it the y will do animate

play14:40

question mark uh maybe negative seven

play14:44

otherwise zero so it should look like

play14:46

it's moving up and down now

play14:49

moves up a little moves down a little

play14:51

bit and

play14:52

now it's moving up let's put a little

play14:54

extra spacing between these two items

play14:57

so underneath the text here i'm going to

play14:58

call dot padding

play15:00

edges of bottom and then maybe 20.

play15:06

it should move it down a little

play15:09

and finally let's add a little bit of

play15:11

shadow onto this i think the shadow will

play15:13

make it really cool and let's animate

play15:14

the shadow as well

play15:16

so after the padding we'll call dot

play15:19

shadow

play15:20

and we're going to use the color and

play15:21

radius completion

play15:24

and let's put all of these all these

play15:25

parameters on separate lines

play15:32

and my computer sounds like it is going

play15:34

to overheat the fan is going crazy so

play15:37

i think it's because that animation was

play15:38

running but uh i'm gonna take a break

play15:40

real quick so you don't have to listen

play15:42

to this fan and

play15:43

be right back all right so

play15:46

let's animate the color of the shadow

play15:49

the same way we're animating this color

play15:52

here so i'm just gonna copy this

play15:54

and let's put it on the shadow but

play15:57

instead of the full color let's call dot

play15:59

opacity of 0.7 on both of these

play16:03

call it after the accent color as well

play16:07

just because the shadow usually

play16:08

shouldn't be as strong as the actual

play16:10

the actual button color uh for the

play16:13

radius let's animate it so we'll call

play16:15

animate

play16:15

question mark and we'll make it fairly

play16:18

big when it's animating so

play16:19

30 otherwise 10.

play16:22

and we should see the shadow behind the

play16:24

button a little bit now

play16:26

uh let's keep the x as zero and

play16:29

the y let's also animate so i want to

play16:31

push it down a little bit so it's below

play16:33

the button

play16:34

because our button is hovering upward so

play16:36

we'll do animate

play16:37

question mark uh maybe 50 otherwise

play16:40

30. so this is kind of the same amount

play16:44

as

play16:44

it's kind of the opposite of the padding

play16:47

so our

play16:48

our shadow is below it now and i think

play16:50

this is going to look really cool if we

play16:52

press

play16:52

play so let's hit play on the live

play16:55

preview and now we have our button

play16:57

and it should look like it's kind of

play16:58

hovering a little bit which is cool and

play17:00

the shadow is animating

play17:01

with the button which looks really

play17:04

natural

play17:04

i like it all right and now the last

play17:07

thing i want to do in this video is just

play17:09

update these colors because

play17:10

this blue is the accent color and the

play17:13

accent color

play17:14

and when we've been coding all of our

play17:16

buttons that default to blue

play17:18

that's all because the accent color is

play17:20

by default blue

play17:21

but we can customize this accent color a

play17:24

little bit

play17:25

and i also want to change out this red

play17:27

color because i want this to be a custom

play17:29

color as well

play17:30

so we're going to create an accent color

play17:32

as well as a secondary accent color that

play17:33

we're going to put

play17:34

here to update the accent color globally

play17:37

across our entire app

play17:39

we can open up the navigator go to the

play17:42

assets folder and there is a

play17:44

accent color that's already in the

play17:47

folder

play17:47

and by default it is blue but we can

play17:50

click it

play17:50

here and then customize it by opening up

play17:53

the inspector

play17:56

we can then click on show color panel

play17:58

and here we can change the color to

play17:59

whatever we want

play18:01

i'm on the crayons tab and i'm going to

play18:03

use this dark purple here

play18:06

i think this is going to be a cool

play18:07

purple so this is the eggplant color

play18:10

i'm going to close out of this so now

play18:12

our accent color instead of blue is

play18:14

purple

play18:15

and i'm going to right click on this

play18:17

column here

play18:18

create a new color set let's call it

play18:23

secondary accent color

play18:28

and the secondary accent color i'm going

play18:30

to change the appearance to

play18:32

none for now so now right now it's just

play18:35

white

play18:35

but let's click on it let's open the

play18:37

color panel and i'm going to make this a

play18:39

different button than our purple because

play18:40

it's going to animate

play18:41

from this purple to this new color i'm

play18:44

going to pick this maroon

play18:46

because this looks like it could be kind

play18:48

of natural going from purple to maroon

play18:50

instead of like

play18:50

purple to yellow but you're welcome to

play18:54

use whatever color you want here of

play18:55

course

play18:56

i'm going to close out of this and now

play18:59

we have our secondary accent color so

play19:01

let's go back into the no items view

play19:05

and i'm going to hide the navigator hide

play19:10

the inspector as well we don't need that

play19:13

and this color red let's change out

play19:16

for our new color but we're also going

play19:18

to call it down here we have color red

play19:20

so since we're going to call it twice

play19:21

i'm going to actually make it a variable

play19:23

at the top of our screen

play19:25

so up underneath this animate let's call

play19:27

let

play19:28

secondary accent color

play19:33

equals color open the parentheses we're

play19:35

gonna use the name

play19:37

and it's going to be secondary accent

play19:39

color

play19:40

this is the name we just gave it in the

play19:42

assets.xc assets folder

play19:44

and let's take this secondary accent

play19:46

color and where we have color red

play19:48

we'll use that and down here as well

play19:51

color red instead we'll call secondary

play19:53

color

play19:54

secondary accent color.opacity if i

play19:56

click resume on the

play19:58

canvas we should now see our colors

play20:02

build in if it's not building click

play20:04

command

play20:05

shift k to clean and rebuild and then

play20:08

the new color should come in so the

play20:10

accent color is purple

play20:12

and when we animate we should animate

play20:14

from this purple to that maroon

play20:17

and this is looking pretty cool all

play20:19

right and the last thing we're going to

play20:21

do now

play20:21

is put the no items view into the rest

play20:24

of our app so let's open the navigator

play20:26

let's open up the list view and where we

play20:29

have

play20:30

no items instead we're going to add our

play20:33

no items view open and close the

play20:36

parentheses

play20:38

so let's click run on the simulator and

play20:41

test it out and see if it all looks good

play20:46

all right so 1.5 seconds in we have our

play20:48

animation

play20:49

starting uh and if we click on this we

play20:52

should navigate to the next screen

play20:54

awesome and when we come back the

play20:56

animation should still be going

play20:58

which it looks like it is let's try one

play21:00

more time we'll go add and we'll go back

play21:03

and this is looking great and if we add

play21:05

an item it should then go away

play21:07

so i'll say my first item

play21:10

save and now we have this screen of

play21:13

course

play21:14

we can toggle it we can then delete it

play21:16

and when we delete it

play21:17

our note items should be back let's

play21:20

finish this up by actually adding a

play21:21

little bit of transition there so that

play21:23

it didn't just pop on the screen it

play21:25

actually kind of animated onto the

play21:26

screen

play21:27

so let's take this new items view let's

play21:29

call

play21:30

dot transition and we'll call any

play21:34

transition

play21:35

dot opacity dot

play21:38

animation dot ease in

play21:42

so this should give a little bit of

play21:43

animation when this comes onto the

play21:45

screen

play21:46

let's click run on the simulator one

play21:47

final time

play21:52

and our animation should start and let's

play21:55

add an item

play21:59

and that's working and then when we

play22:01

delete it our new screen should kind of

play22:04

animate the opacity when it comes onto

play22:06

the screen

play22:08

and it did that looks really cool all

play22:10

right everyone

play22:11

thank you all for watching that's it for

play22:13

this video we are very close to being

play22:15

done with his app

play22:16

i hope you guys are liking it it's

play22:18

looking really cool as always

play22:20

i'm nick and this is swiffle thinking

play22:22

and i'll see you in the next video

play22:28

[Music]

play22:30

you

Rate This

5.0 / 5 (0 votes)

Related Tags
Swift UI待办事项应用用户体验动画设计颜色定制Xcode开发界面优化编程教程交互设计应用开发iOS开发
Do you need a summary in English?