Glen T
Glen T

Reputation: 1550

"Fixing" a sub-view within a UIScrollView

I have a UIScrollView which contains a view (lets call this "main view") which scrolls along the X and Y axis.

I am trying to transparently overlay a heading over this view which is fixed at the top of the screen (not view) but scrolls along the X axis as the main view does. When the main view scrolls along the Y axis the heading remains at the top of the screen.

What would be the best approach to achieve this?

Upvotes: 0

Views: 1953

Answers (2)

Rog
Rog

Reputation: 17170

Create a container view for both your indicator view and the scrollview. Make it the size of the screen.

Add both the UIScrollView and your HeadingView to this as Subviews. The Heading will then stay still as the scrollview pans. You can update the heading based on messages to a UIScrollViewDelegate you add to the Scrollview. scrollViewDidScroll: is the most obvious but you can get other notifications.

Upvotes: 2

Alex Wayne
Alex Wayne

Reputation: 187004

I would not put the view in the scrollview at all. Use the scroll view delegate to catch when the scroll view is panning and move your subview horizontal manually.

Upvotes: 1

Related Questions