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

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

问题描述

我有一个画布,让尺寸500x600.I有canvas.User里面的一些控件可以通过拖放drop.But重新排列控件的说,我要限制的拖放的画布中。

例如:有一个在canvas.User一个按钮就可以任意拖放按钮的canvas.But内,如果用户试图将按钮出了画布边界的,应该坚持在画布边界<。 / P>

如何实现这一目标?

解决方案

的startDrag()的签名公共职能的startDrag(lockCenter:布尔=假,范围:矩形= NULL):无效

第二个参数,可以传递一个矩形作为界限的的DisplayObject 。它不会被外部此拖

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.

How to achieve this?

解决方案

The signature for startDrag() is public function startDrag(lockCenter:Boolean = false, bounds:Rectangle = null):void

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天全站免登陆