There is one part of a page in the project that needs to scroll across multiple pictures horizontally. It is natural to think of using Uiscrollview, the specific implementation is very easy, the first to do a demo, the effect is as follows:
But add this viewcontroller to a uinavigation, the result is completely different, as follows:
The reason is also easy to analyze, nothing but Uiscrollview Contentinset has been changed, it is easy to verify this argument, in Viewdidappear will Uiscrollview object Contentinset value to print out.
Now the thing to do is to solve this problem, the object of course is the Uiscrollview object Contentinset attribute, set it to be UIEdgeInsetsMake(0, 0, 0, 0) , but where set up, the author in Viewdidload, Viewwillappear and Viewdidappear have tried all of these callback functions, but have failed.
Later consulted StackOverflow, finally found a solution: in the corresponding Viewcontroller implementation Viewdidlayoutsubviews method, and then set the Contentinset property of the Uiscrollview instance, As follows:
-(void) Viewdidlayoutsubviews { self.scrollView.contentInset = uiedgeinsetsmake (0, 0, 0, 0); [Super Viewdidlayoutsubviews];}
The author of the Cheap hand, found in the viewwilllayoutsubviews treatment can also solve the problem; even after a few days, Find another solution to the problem: setting the translucent property of the associated Uinavigationcontroller Navigationbar is false.
There are several ways to set the Viewcontroller property automaticallyadjustsscrollviewinsets to False.
In fact, the reason is simple, in the iOS official document "View Controller Catalog for IOS" can find the answer.
Uiscrollerview met Uinavigationcontroller