I would like to display an image (width: 320 pixels, height: 1250 pixels) in an image view.
When I compile the application I get no scrolling at all. The view stays fixed.
What I did:
- Added an
UIScrollView
via Interface Builder to my view. - Added an
UIImageView
via Interface Builder to my view. - Verified that
UIImageView
is belowUIScrollView
in Interface Builder. - Set the size of the
UIScrollView
withViewDidLoad
.
How do I do this?
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
scrollView.contentSize = CGSizeMake(320, 1250);
}
Screenshots:
ImageView
:
ScrollView
:
From you last screenshot and from your comments it looks like your scrollView is way to big. The scrollview must be visible on screen completely. For example a full screen UIScrollView on iPhone would have a size of 320 x 460.
If the scrollview is the same size as its content you can't scroll.
The greenish rectangle shows the size of your scrollview, the pinkish the size of your content (your image):
Don't forget to add the
categoryprotocol to the interface, like thisIf you don't, you will not be able to set the scroll view delegate to self
(i.e.
[MyScrollView setDelegate:self];
)If you do this, it should work.
My code is:
Since Xcode 5 it does not work like before. Also scrolling to the end of a scrollable text field makes problems. There are also differences between doing it on iPhone or iPad. On iPhone it worked without delayed timer.
This worked for me:
I had the same issue and was looking for the answer in this thread. I tried all the stuff, but nothing works. Then I found this:
.
You just need to deselect "Use Auto Layout" in File Inspector of your
ViewController
. Ta-Da, it works immediately for me. Enjoy.Swift 4, iOS 11
The simplest way using autolayout:
Did you assign the scroll's view delegate? Always remember these: