I have several draggable views in a project, and their view hierarchy is set when you drag them into the window in IB --that is, the last one you drag in appears on top of all the others and the first one appears under all the others when you drag them around. I want to make the one I am currently dragging appear on top of all the others, but can’t figure out how to do that. I tried sending viewWillMoveToSuperview_(mainView) to the view I’m dragging but that didn’t do anything. Any ideas?
Actually, I figured out one way to do this myself. You get the list of all the subviews of the main view, populate a mutable array with that list, figure out the index of the object you picked up to drag, exchange it with the object with the highest index number in the array, and finally, reset the subviews:
Set up the array first:
set mlist to my subviews() --the main content view is set to the script's class, so "my" refers to the main content view set letterPool to NSMutableArray's alloc()'s init() letterPool's addObjectsFromArray_(mlist)
then in the mouseDown method:
set mouseLoc to (theEvent's locationInWindow()) as record set thing to hitTest_(mouseLoc) --returns the object clicked on set myIndex to letterPool's indexOfObject_(thing) letterPool's exchangeObjectAtIndex_withObjectAtIndex_(myIndex, 10) --10 is the highest index in this array my setSubviews_(letterPool)
Now, the object that was picked up and dragged is the top most item (visually) when dragged around.