如何限制画布中的拖放区域 [英] How to restrict the drag and drop area in a canvas

查看:23
本文介绍了如何限制画布中的拖放区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个画布,可以说尺寸为 500x600.我在画布内有一些控件.用户可以通过拖放来重新排列控件.但我想限制该画布内的拖放.

I have a canvas,lets say of dimensions 500x600.I have some controls inside that canvas.User can rearrange the controls by drag and drop.But I want to restrict the drag and drop within that canvas.

例如:画布中有一个按钮.用户可以将按钮拖放到画布内的任意位置.但是如果用户试图将按钮拖出画布边界,它应该会停留在画布边界内.

For example:There is a button in the canvas.User can drag and drop the button anywhere inside the canvas.But if the user tries to drag the button out of the canvas boundaries,it should stick in the canvas boundary.

如何实现这一目标?

推荐答案

startDrag() 的签名是 public function startDrag(lockCenter:Boolean = false, bounds:Rectangle = null):void

第二个参数允许你传递一个 Rectangle 来作为你的 DisplayObject 的边界.不会被拖到外面

The second parameter allows you to pass a Rectangle to act as bounds for your DisplayObject. It won't be dragged outside of this

这篇关于如何限制画布中的拖放区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆