I have put an UIImageView and a UITextView in a UIScrollView. The result is that when I scroll, the text scrolls but the image stays on the same place.
Is it possible to make the UIImageView and UITextView to scroll as a whole? Can this be done using the storyboard?
The reason that you are only scrolling the text is that the UITextView has its own UIScrollView and you are only scrolling the UITextViews internal scroll view.
To achieve what you are looking for you need to:
Disable scrolling in the UITextView
Set
scrollingEnabledto false on your textview, this can be done directly in the storyboard.Resize the UITextView
The text view could cover any length of text and without knowing what text is being set, you can’t set the correct size. I.e, you will need to set the size in code when the text is set in the UITextView.
Resize the contentSize
See above (if you don’t know the height of the UITextView you can’t know the content size).
Layout the UIImageView and the UITextView in the UIScrollView
You can however layout the UIImageView and the UITextView in the storyboard and only change the
boundsof the text view and thecontentSizeof the scrollView when the text is set.View hierarchy
The image below shows how your view hierarchy should look when you are finished. The frame of the scrollView is blue. Its content is red and is bigger than the frame. Within lies the image view (yellow) and the text view (green).