简体   繁体   English

如何在 swiftui 中使用拖动手势缩放元素

[英]How to scale a element using Drag gesture in swiftui

my example image我的示例图片

Here, in my example image you can see that I have a text "HELLO" and in the right corner having a button.在这里,在我的示例图像中,您可以看到我有一个文本“HELLO”,并且在右上角有一个按钮。 I want that I can scale my text or element by Drag gesture of the right corner button.我希望我可以通过右上角按钮的拖动手势来缩放我的文本或元素。 What is the efficient way?什么是有效的方法?

  • first, you need to add a Gesture to the scaling view so that when you drag it in the required way do action首先,您需要将 Gesture 添加到缩放视图,以便在以所需方式拖动它时执行操作
  • secondly, you need to add the height and width constraints to the viewController of the scaling view其次,需要在缩放视图的viewController中添加高宽约束
  • in last, you need to add a func that animates the width and height by increasing or decreasing the size depending on the gesture最后,您需要添加一个函数,通过根据手势增加或减小大小来设置宽度和高度的动画

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM