swiftui_SwiftUI中的神经形态设计

swiftui

Neumorphic Design is a new take on Skeomorphic design, which was used when iPhone first came out. In Skeomorphic design elements were styled to resemble real world objects. Neumorphic design allows the elements to blend into the background.

Neumorphic Design是Skeomorphic设计的一种新形式,最初在iPhone推出时就使用过。 在Skeomorphic设计中,元素的样式类似于真实世界的对象。 中性设计允许元素融合到背景中。

Neumorphic design always reminds me of Terminator 2 villain. He was able to walk through objects and blends in with other objects like he was made of thick liquid (Mercury).

神经形态的设计总是让我想起《终结者2》的反派。 他能够穿过物体并与其他物体融为一体,就像他是由浓稠液体制成的(水星)一样。

Image for post
https://lh3.googleusercontent.com/proxy/1s8N1S-qg4LZecWtCUgL_FmsiXrq7KoXmVI-cjJGdywnthFFFX6Fr_5ejpRkbBrawjuwjmBfMos3396S9vE9kLQU1xsQzydhLjhvvRwvXizzG0BzFyUD9qJh_hQcGBPgnesmPQu5qMevkUmjfFKAQCTvSZQC4bS7XlpF https://lh3.googleusercontent.com/proxy/1s8N1S-qg4LZecWtCUgL_FmsiXrq7KoXmVI-cjJGdywnthFFFX6Fr_5ejpRkbBrawjuwjmBfMos3396S9vE9kLQU1xsQzydhLjhvvRwvXizzG0BzFyUD9qJh_hQcGBPgnesmPQu5qMevkUmjfFKAQCTvSZQC4bS7XlpF

创建神经变形按钮 (Creating the Neumorphic Button)

We will start our journey by implementing the look and feel of the Neumorphic Button. Add a brand new file called “NeumorphicImageButton” which conforms to the View protocol. In order to create NeumorphicImageButton, you must pass in the systemName for the image and the onTap closure. The onTap closure will be fired when the user taps on the button.

我们将通过实现Neutralic Button的外观开始我们的旅程。 添加一个符合View协议的全新文件“ NeumorphicImageButton ”。 为了创建NeumorphicImageButton,必须为图像和onTap闭包传递systemName。 当用户点击按钮时,将触发onTap关闭。

Next, we create a Button view inside the NeumorphicImageButton implementation. An Image view is used inside the content of the Button, which uses the systemName property to set the image. In order to make the button round, we have used the clipShape function to clip a Circle shape. Finally, we used the shadow function to create multiple shadows on the Button. The shadow creates the floating effect, which become the essense of Neumorphic design.

接下来,我们在NeumorphicImageButton实现内部创建一个Button视图。 在Button的内容内部使用Image视图,该按钮使用systemName属性设置图像。 为了使按钮变圆,我们使用了clipShape函数来裁剪圆形。 最后,我们使用阴影函数在Button上创建了多个阴影。 阴影会产生浮动效果,这成为Neumorphic设计的本质。

If you run the app, you will be able to see the following output.

如果您运行该应用程序,则将看到以下输出。

Image for post

Looks pretty good right!

看起来还不错吧!

使按钮可插入 (Making Button Tappable)

By default NeumorphicImageButton is already tappable because it is based on a Button but it does not feel right. We need to adjust the button so it feels that it become part of the background when it is tapped. This is accomplished by shadows, scaling effect and animations.

默认情况下,NeumorphicImageButton已经可以轻按,因为它基于Button,但是感觉不正确。 我们需要调整按钮,使其在被点击时感觉成为背景的一部分。 这是通过阴影,缩放效果和动画来完成的。

We captured the pressed state of the button in the state variable. When the button is pressed we set the isPressed property to true. Since this is a state property, each time you set the property the body is rendered again.

我们在状态变量中捕获了按钮的按下状态。 当按下按钮时,我们将isPressed属性设置为true。 由于这是状态属性,因此每次设置该属性时,都会再次渲染主体。

Based on the state we apply different shadow color and scaleEffect to the Button. To make sure that the button comes up after it has been depressed we used the DispatchQueue asyncAfter and set the isPressed to false after 0.2 seconds.

根据状态,我们将不同的阴影颜色和scaleEffect应用于Button。 为了确保在按下按钮后按钮会出现,我们使用了DispatchQueue asyncAfter并将0.2秒后的isPressed设置为false。

The effect is shown below:

效果如下图所示:

Image for post

Pretty sweet!

太甜了!

Just like other design changes, Neumorphic design has been received by the community with mixed reactions. Personally I love it, and I think it creates very simplistic and futuristic looking apps.

就像其他设计更改一样,Neumorphic设计也受到了社区的不同React。 我个人很喜欢它,并且我认为它创建了非常简单且具有未来感的应用程序。

资源资源 (Resources)

  1. YouTube Video: Neumorphic Design in SwiftUI

    YouTube视频:SwiftUI中的中立设计

  2. SwiftUI — Declarative Interfaces for any Apple Device

    SwiftUI —任何Apple设备的声明性接口

翻译自: https://medium.com/swlh/neumorphic-design-in-swiftui-643f252f7267

swiftui

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值