按钮 交互_SwiftUI中的微交互—菜单按钮动画

按钮 交互

Microinteractions have become increasingly important in a world with a dizzying number of digital platforms and an ocean of content. While microinteractions used to be considered an interesting resource in the early days of digital design, in today’s hypercompetitive digital space they have become a crucial element in the overall user experience.

在拥有令人眼花number乱的数字平台和无数内容的世界中,微交互变得越来越重要。 尽管微交互在数字设计的早期曾被视为一种有趣的资源,但在当今竞争激烈的数字空间中,微交互已成为整个用户体验中的关键要素。

Basically, a microinteraction is a particular moment of a user’s interaction with a product in order to complete a specific task. For example, when someone presses a “Like” button (whatever it looks like) and sees that their action produced feedback — the number has changed, the color of the button has changed or it has become inactive, the text on the button reported that the action was done and so on — this is a case of microinteraction.

基本上,微交互是用户与产品进行交互以完成特定任务的特定时刻。 例如,当某人按下“赞”按钮(无论其外观如何)并看到他们的动作产生了反馈-数字已更改,按钮的颜色已更改或已变为无效状态时,该按钮上的文字会报告操作已完成,依此类推-这是微交互的情况。

The idea here is to present a menu button with 4 horizontal lines, and, when the user taps on the button, it animates into an ‘x’ shape, to represent the option of closing the menu.

这里的想法是呈现一个带有4条水平线的菜单按钮,当用户点击该按钮时,它会动画化为“ x”形,以表示关闭菜单的选项。

Image for post

I began with an empty project, enabling SwiftUI. Then I created a file with two views, like this:

我从一个空项目开始,启用了SwiftUI。 然后,我创建了一个具有两个视图的文件,如下所示:

I defined a fixed frame for it, and for my purposes it can be a square shaped button. There’s a state property isAnimating, that the animations will respond to.

我为此定义了一个固定框架,出于我的目的,它可以是方形按钮。 有一个状态属性isAnimating ,动画将对其进行响应。

For the button body the action is simply to toggle the isAnimating property, and its label closure calls the createMenu method. Let's take a look at it.

对于按钮主体,操作仅是切换isAnimating属性,其标签闭合调用createMenu方法。 让我们来看看它。

There’s a lot going on here, but I’ll break it down. First, the method returns a type eraser view AnyView, and contains two properties, the count, which is the number of rows for the button, and the configuration of the menu.

这里有很多事情,但我会分解。 首先,该方法返回一个类型的橡皮擦视图AnyView ,并包含两个属性: count (按钮的行数)和菜单的配置。

In menu the geometry reader is used, so that we can access the width and height we have available, and, therefore, calculate the properties we need. So, 4 views are grouped, and we calculate availableHeight, spacing, height and width.

menu ,使用了几何图形读取器,以便我们可以访问可用的宽度和高度,从而计算所需的属性。 因此,对4个视图进行了分组,然后我们计算了availableHeightspacingheightwidth

Image for post

Then, the rectangles are created with the height and width, and we can finally configure them. Each rectangle is overlapping the other ones, so we’ll use the offset modifier and multiply the index by the available height. This way they get positioned correctly along the y axis.

然后,使用高度和宽度创建矩形,最后我们可以对其进行配置。 每个矩形都与其他矩形重叠,因此我们将使用offset修饰符并将索引乘以可用高度。 这样,它们就可以正确地沿y轴定位。

Then I configured the animations, which are custom modifiers. I’ll get to them in a second. Finally I used the animation modifier, with a small delay and the easeInOut option, and return the menu.

然后,我配置了动画,它们是自定义修改器。 一会儿,我会去找他们。 最后,我使用了animation修改器( easeInOut延迟)和easeInOut选项,然后返回菜单。

配置动画 (Configuring the Animations)

The MiddleMenuRect is a custom modifier that handles the second and third rectangles (index '1' and '2'). Both of them need to rotate, on opposite directions.

MiddleMenuRect是一个自定义修饰符,用于处理第二个和第三个矩形(索引“ 1”和“ 2”)。 它们都需要沿相反的方向旋转。

Here’s how the code look like:

代码如下所示:

In the body function, two modifiers are being called: rotate and offset. That's because when the rect is rotated there's a slight difference in position, so they need to me adjusted in order to form the 'x'.

在body函数中,调用了两个修饰符: rotateoffset 。 这是因为当旋转rect时,位置略有不同,因此需要对它们进行调整以形成“ x”。

The modifiers return a value based on a condition of being the middle indexes and the isAnimating boolean.

修饰符基于成为中间索引和isAnimating布尔值的条件返回值。

For the MarginMenuRect the setup is very similar, but this time, the first and last indexes are placed as conditions and the modifiers opacity and offset are applied. While the rectangles are moved through the 'x' axis in different directions, the opacity is reduced, giving the idea that they were 'removed'. Check out the code:

对于MarginMenuRect的设置非常相似,但是这次,第一个和最后一个索引作为条件放置,并且应用了修饰符opacityoffset 。 当矩形沿“ x”轴沿不同方向移动时,不透明度降低了,从而产生了“已删除”的想法。 签出代码:

For better readability, the MiddleMenuRect and the MarginMenuRect view modifiers were added to an extension:

为了提高可读性,在扩展中添加了MiddleMenuRectMarginMenuRect视图修饰符:

That’s it! We have a nice menu button, that when tapped turns into an ‘x’. Here’s how it looks in action:

而已! 我们有一个不错的菜单按钮,当您点击它时,它会变成一个“ x”。 实际效果如下:

Image for post

Nice, isn’t it?

很好,不是吗?

Utilising microinteractions can enrich usability. The features of an app attract a user to the product, but the details more then often make a huge difference. This was an example of how a microinteraction can be implemented in SwiftUI and give a nice touch to your apps.

利用微交互可以丰富可用性。 应用程序的功能吸引了用户使用该产品,但是更多的细节通常会带来巨大的不同。 这是一个示例,说明了如何在SwiftUI中实现微交互并为您的应用程序提供良好的体验。

Developing it was fun, and it was pleasant to see the animation in place. If you want to see the full code, here’s the gist. Thanks for reading!

开发它很有趣,并且很高兴看到动画到位。 如果您想查看完整的代码,这是要点 。 谢谢阅读!

Originally published at https://vinileal.com on April 11, 2020.

最初于 2020年4月11日 发布在 https://vinileal.com 上。

翻译自: https://uxdesign.cc/microinteractions-in-swiftui-menu-button-animation-5d60f802fe5d

按钮 交互

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/275011.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

选择控件— UI组件系列

重点 (Top highlight)The word “toggle” is a reference to a switch with a short handle that alternates between two states each time it is activated. You encounter it every time you “switch” on the lights.单词“ toggle”是指带有短手柄的开关,该开…

SEE Conf: Umi 4 设计思路文字稿

大家好,我是若川。持续组织了5个月源码共读活动,感兴趣的可以点此加我微信 ruochuan12 参与,每周大家一起学习200行左右的源码,共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。复制此链接 https:…

用户体验改善案例_改善用户体验研究的5种习惯

用户体验改善案例There’s plenty of misunderstanding around user research, whether it’s the concept of validation or one-off anecdotes being thrown around as concrete evidence for a product decision.用户研究存在很多误解,无论是验证的概念还是一次性…

巴克莱对冲_“巴克莱的财政预算案”:使金钱管理对心理健康有效—用户体验案例研究

巴克莱对冲Disclaimer: all official Barclays assets used for this project are purely for educational/project purposes only and do not reflect the intentions of Barclays or any of its affiliates.免责声明:用于此项目的所有官方巴克莱资产纯粹是出于教育…

6 个对所有 Web 开发者都有用的 GitHub 仓库

作者:Mehdi Aoussiad原文:https://javascript.plainenglish.io/6-useful-github-repositories-for-all-web-developers-44f26912fd66大家好,我是若川。持续组织了5个月源码共读活动,感兴趣的可以点此加我微信 ruochuan12 参与&…

openfiler的iSCSI配置(二)

为什么80%的码农都做不了架构师?>>> 一.openfiler iSCSI配置 1.启动iSCSI target server服务。在Services列表下。 2.设置访问列表。在System---Network Access Configuration下设置。 3.创建卷设备 二.ISCSI客户端配置 1.安装open-iscsi # apt-get ins…

送你一份用Electron开发桌面应用的避坑指南【送3本书,含犀牛书】

大家好,我是若川。持续组织了5个月源码共读活动,感兴趣的可以点此加我微信 ruochuan12 参与,新年第一次送3本书。抽奖规则见文末。如今,Electron 领域发生了重大的变革,Electron 版本更新换代极快,难以计数…

nginx修改upstream不重启的方法(ngx_http_dyups_module模块)

为什么80%的码农都做不了架构师?>>> nginx很强大,第三方模块也不少,淘宝在nginx上很活跃,特别是章亦春,他参与的模块至少10, 好了今天主角不是他,是一款动态配置upstream的模块,这个…

c# 设计原则需要学习吗_向最好的学习:产品设计原则

c# 设计原则需要学习吗重点 (Top highlight)In my job as Design Team Lead at SimpleSite, I’ve recently been part of creating a set of Product Design Principles. In this process, I spent a lot of time studying the theory, learning about best practices, and ge…

Node.js 2021年开发者报告解读

大家好,我是若川。持续组织了5个月源码共读活动,感兴趣的可以点此加我微信 ruochuan12 参与,每周大家一起学习200行左右的源码,共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。很多人觉得Node.js…

搭建nginx反向代理用做内网域名转发

为什么80%的码农都做不了架构师?>>> 情景 由于公司内网有多台服务器的http服务要映射到公司外网静态IP,如果用路由的端口映射来做,就只能一台内网服务器的80端口映射到外网80端口,其他服务器的80端口只能映射到外网的…

外国经典儿童读物合集pdf_帮助父母在线购买儿童读物–用户体验案例研究

外国经典儿童读物合集pdfTŤ As our first group project at GA, we needed to quickly learn how to use several online tools that helped our team of 4 collaborate and communicate while socially distant. Despite the rather extreme circumstances our team was stil…

如何优雅处理 async await 错误——解读小而美的 await-to-js 库

大家好,我是若川。持续组织了5个月源码共读活动,感兴趣的可以点此加我微信 ruochuan12 参与,每周大家一起学习200行左右的源码,共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。这是源码共读活动第…

同态加法_同态的Spotify

同态加法重点 (Top highlight)When neumorphism was predicted to be one of the top 2020 UI design trends, I wanted to give it a shot. Having said that, I wanted to explore a type that had not gone overboard, neumorphism in Dark Mode.当neumorphism预计为顶部202…

ubuntu清除无效的右键打开方式

为什么80%的码农都做不了架构师?>>> 今天安装了几个程序又将它们删除了之后发现了一个比较严重的后遗症,在相关文件右键打开方式中出现了许多实际已经不存在的文件打开程序名。想了多种方法去除,可是效果不佳,最终采用…

新一代的编译工具 SWC,97年小哥写的~

大家好,我是若川。持续组织了5个月源码共读活动,感兴趣的可以点此加我微信 ruochuan12 参与,每周大家一起学习200行左右的源码,共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。最近前端圈掀起了一…

粉红噪音_粉红的常绿力量

粉红噪音I use Instagram. But I don’t use Instagram in the way that my daughters, who are 21 and 14, use Instagram. More to the point, Instagram doesn’t use me in quite the same way it uses my daughters.我使用Instagram。 但是,我不会像21岁和14岁…

Sql Server 中存储过程的output return的区别

看http://zxianf.blog.163.com/blog/static/301207012009114104124969/中片关于Sql Server中存储过程output和return值的区别 在里面有讲解,我在自己本机中测试的结果如下, 1:ReturnValue只能返回0,1,-1这样的数据,局限性很大 &am…

1个月增长15000 star,zx 库写shell脚本真不错~

大家好,我是若川。持续组织了5个月源码共读活动,感兴趣的可以点此加我微信 ruochuan12 参与,每周大家一起学习200行左右的源码,共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。今天来讨论一个牛逼…

灰色边框阴影_50种暗模式灰色阴影

灰色边框阴影If you’re an avid dark mode user like me, you’ll know that dark mode isn’t just about white text on black backgrounds. In a single app, a handful of shades of gray give the app some depth. And across various apps, the spectrum of gray become…