J. Wood
J. Wood

Reputation: 43

Swift - Grow and shrink UIView on scroll

I'm very new to iOS and Swift development.

I am working on an app that has a MapView and a ScrollView. I would like to adjust the height of the MapView based on the ScrollView's offset. So when the user scrolls down from the top of the ScrollView the MapView will expand to nearly the full device height and with the user scrolls up from the top of the ScrollView the MapView will shrink and be replaced by a NavigationBar. Below is a gif recorded from an app in the app store to better illustrate what I'm looking for.

Example

I have attempted to modify the code sample found here: http://www.thinkandbuild.it/implementing-the-twitter-ios-app-ui/

But can't seem to get it figured out.

I greatly appreciate any help.

Upvotes: 2

Views: 1799

Answers (1)

Niall Kiddle
Niall Kiddle

Reputation: 1487

What you need to use is a property animator where you state the animation that you want to be done and use the scroll view's offset to track the progress through the animation. I have used it lots in my app before and used this tutorial which was very useful.

http://www.swiftkickmobile.com/building-better-app-animations-swift-uiviewpropertyanimator/

Upvotes: 1

Related Questions