Travis Griggs Travis Griggs - 5 months ago 10
iOS Question

Best way to have "float over" controls for a UICollectionViewController?

I have a

setup. It shows something kind of like a gantt chart, with selectable bars, scrolling, etc. I want to have a "trash/delete" button that always floats in the bottom right of the screen, regardless of scroll. It will delete the current selection (if there's one) in the

I see two basic approaches:

  1. Use the Supplementary Views facility of my
    . What I dread about this, is that I'll have to muck with its layout in my layout (I'm using my own subclass of
    ) to keep it positioned in the bottom right corner, regardless of scroll.

  2. Just add a UIButton to the canvas and set it up there. Maybe this isn't even a real approach, because this is what I wanted to do. While my button may manipulate items found in the
    , it's not really a real member of the collection view. But I found when I tried to drag a UIButton onto my Controller in the storyboard, it wouldn't stick. It doesn't seem to want to add it. Do I have to change to use a
    , and then have a top level view that I can add both my button and collection view into? And then repeat all of the handy delegate/property setup that I get for free from



drag a button on to the view

in storyboard/xib.

Then, in the hierarchy column on the left, ensure it is at the bottom. That means it will be in front of everything else.

So, if necessary move it so it is in front of (ie, below in hierarchy) the collection view.

Note that there is absolutely no problem, at all, with putting one control "in front of" the other (i.e., so that it "blocks" you from seeing all or part of the other one).

If you had a problem doing this, you've made a trivial mistake. For example you may have dragged the new button "into" the collection view, rather than as a "sibling of" the collection view. Hope it helps.