automaticallyAdjustsScrollViewInsets not working
I think that automaticallyAdjustsScrollViewInsets
only works when your controllers view
is a UIScrollView
(a table view is one).
You're problem seems to be that your controller's view
is a regular UIView
and your UITableView
is just a subview, so you'll have to either:
Make the table view the "root" view.
Adjust insets manually:
UIEdgeInsets insets = UIEdgeInsetsMake(controller.topLayoutGuide.length,
0.0,
controller.bottomLayoutGuide.length,
0.0);
scrollView.contentInset = insets;
Edit:
Seems like the SDK is capable of adjusting some scroll views despite not being the controller's root view.
So far It works with UIScrollView
's and UIWebView
's scrollView
when they are the subview at index 0
.
Anyway this may change in future iOS releases, so you're safer adjusting insets yourself.
CollectionView AutomaticallyAdjustsScrollViewInsets not working properly
On ios 11, if you want to disable the feature what AutomaticallyAdjustsScrollViewInsets
did before, we should use ContentInsetAdjustmentBehavior
. Firstly set AutomaticallyAdjustsScrollViewInsets
to false in the ViewDidLoad()
event to adapt lower iOS versions. Then on iOS 11+ add the code below:
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
if (!AutomaticallyAdjustsScrollViewInsets)
{
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
MyCollectionView.ContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.Never;
}
}
else
{
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
MyCollectionView.ContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.Automatic;
}
}
}
At last you can set the CollectionView's ContentInset manually to fit your request.
automaticallyAdjustsScrollViewInsets' was deprecated in iOS 11.0
The default for this property is now true. If you need to set this, you will need to set it in the scrollview that would host the viewController and set its property contentInsetAdjustmentBehavior. Below is an example:
scrollView.contentInsetAdjustmentBehavior = .automatic
How does UIViewController's automaticallyAdjustsScrollViewInsets work anyway?
From what I know
automaticallyAdjustsScrollViewInsets
allows the view controller to adjust its scroll view insets in
response to the screen areas consumed by the status bar, navigation
bar, and toolbar or tab bar
- works on the view which is direct subview (someone says it must be
the first subview) of the View Controller 's view - this view must be a ScrollView subclass
- the View Controller is embedded in Navigation Controller or TabBar
Controller edgesForExtendedLayout
isUIEdgeRectTop
(if you want the ScrollView
subclass view to be behind the top bar), UIEdgeRectBottom (if you want
the ScrollView subclass view to be behind the bottom bar)
The code below replicates what automaticallyAdjustsScrollViewInsets
does when edgesForExtendedLayout = UIEdgeRectTop
self.scrollView.contentInset = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, 0, 0);
self.scrollView.contentOffset = CGPointMake(0, -self.topLayoutGuide.length);
disable auto adjust uitableView inset
I found the perfect solution!
UITableView.appearance().contentInsetAdjustmentBehavior = .never
just add this code in UITableViewController. and strange adjust inset all gone!
Manually Trigger `automaticallyAdjustsScrollViewInsets` at a Certain Time
It's not an absolutely amazing one, but I found a solution that works.
Inserting a new child view controller isn't enough to trigger UINavigationController
to automatically work out the appropriate contentInset
values for any scroll views in the new child. BUT! You can force it to perform that calculation by doing something that would have required it anyway. For example, hiding and showing the navigation bar or toolbar.
- (void)insertViewController:(UIViewController *)viewController
{
// Add the view to our view
viewController.view.frame = self.view.bounds;
[self.view addSubview:viewController.view];
// Add the new controller as a child
[self addChildViewController:viewController];
[viewController didMoveToParentViewController:self];
// Show and hide the toolbar to force the content inset calculation
self.navigationController.toolbarHidden = YES;
self.navigationController.toolbarHidden = NO;
}
I've tested it, and there appear to be no visual glitches by rapidly hiding either the navigation bar or toolbar, so this solution seems to be acceptable.
Related Topics
Open Phone Settings Programmatically in iOS9
Performance Testing in Swift Using Tdd
How to Put the Image on the Right Side of the Text in a Uibutton
What Is the Life Cycle of an iPhone Application
Uicollectionview Set Number of Columns
Swift - Which Types to Use? Nsstring or String
Remove Grey Background on Link Clicked in iOS Safari/Chrome/Firefox
Fix CSS Hover on Iphone/Ipad/Ipod
Issue with Code Autocompletion/Syntax Highlighting in Xcode 4.X
iOS 8 - Buttons in Horizontal Scroll View Intercepting Pan Event - Scroll Does Not Work
Implementing Hmac and Sha1 Encryption in Swift
Differences Between Udid and Uuid
How to Save a Uicolor with Userdefaults
Custom Rounding Corners on Uiview
Failed to Emit Precompiled Header for Bridging Header
It's Possible to Change Push Notification Message Before Display on Device from iOS Side
Including Custom Data into iOS Crash Dumps
Cannot Assign a Value of Type "String" to Type "Uilabel" in Swift