UIScrollView is moving up if I hide the NavigationBar and the ToolBar

1.5k views Asked by At

I have a problem, I created a zoomable UIImageView with a UIScrollview, everything works perfect, exept the UIImageView is not in the center anymore and every time I hide the Tool- and NavigationBar the UIImageView/UIScrollView is moving up.

I already set the autoresizingMask:

scrollView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    scrollView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;

but it won't work, can someone please help me?

2

There are 2 answers

1
Nour Helmi On

Just like @Mert answered, you can either set it in code self.automaticallyAdjustsScrollViewInsets = NO; or you can set this in storyboard, in the scroll view in one of the inspectors you can un-check the checkbox that automatically adjusts the scroll view content.

EDIT

The checkbox is in the attributes inspector of the UIScrollView, it's called Autoresize Subviews under drawing section.

Btw, this behaviour only happens in iOs7, because of the transparent UINavigationBar thing.

2
Mert On

I had the same problem with iOS 7, and read I had to set

self.automaticallyAdjustsScrollViewInsets = NO;

for the view controller, but it did not work for me. After I have released I had to put it in viewDidLoad method of the parent view controller of the view controller.