-->

Making a pull out tray - (iOS)

2019-09-15 02:49发布

问题:

I'm making an iPad app, and basically, I want to make a tray that pulls out from the bottom of my app, and I'd like to have a little tab at the bottom of the screen that if you pull, it brings up an image, and the image's height would match the height you pulled the button to. It's a bit like how the notification center works, except the tab is always visible.

So my question is how would I have the image follow the tab as it moves vertically across the screen? I would assume using a UIButton for the tab and a UIImage for the tray would make sense, and I have some code for making buttons move, but how can you make one object follow another?

Thanks for your help, -Karl

回答1:

I wouldn't use a button for the tab -- just a regular old view.

To make your image follow the tab (however you implement either of them), simply animate them both together. That is, if you create an animation that moves the center of the button to the Y-coordinate of the user's touch, you can at the same time move the image vertically by the same amount. The two objects will then seem glued together because they move together.