How to implement multiple PanGestures (Draggable views)?

后端 未结 3 872
后悔当初
后悔当初 2021-01-27 06:39

I want to have several objects that I can drag and drop.

Here\'s my code for moving one object (with lot of help from @vacawama):

import UIKit

class Vie         


        
3条回答
  •  孤城傲影
    2021-01-27 07:18

    The way a gesture recognizer works is that you attach it to a view. So if you have multiple views, and you want them to be draggable in the same way, attach a different pan gesture recognizer to each one.

    Now let's say you want them all to have the same action handler. No problem. In the action handler, you receive the current gesture recognizer as a parameter. It has a view property; that's the view it is attached to! So now you know that that's the view you're moving.

提交回复
热议问题