Roman Volkov
Roman Volkov

Reputation: 237

Strange top spacing for ScrollView

enter image description here

enter image description here

I settled the scrollview and the image should be at the top. But when I pushed this view on navigation controller it adds some strange spacing at the top

            if let destination = self.storyboard?.instantiateViewControllerWithIdentifier(StoryboardNames.ItemDetailsView.rawValue) as? ItemDetailsViewConroller {
                destination.itemEntity = updatedItem
                self.navigationVC?.pushViewController(destination, animated: true)
            }

But, I'm opening this view from different navigation controllers. From first the sizing is correct (no spacing at the top), but from another I receive this strange bug. Does anyone know why this is caused?

Upvotes: 1

Views: 117

Answers (3)

Mehul Thakkar
Mehul Thakkar

Reputation: 12594

This thing will be happening if and only if you are adding ScrollView or its subclass(tableview,collectionView,textview etc) at first position in viewController's main view. You can move it to second or any other position or solve by doing following thing:

select your viewcontroller, and see its layout attribute as shown in following image, here uncheck the "Adjust Scroll View Insets". This will stop adding 20 pixel space above.

Upvotes: 0

Rajesh
Rajesh

Reputation: 10424

Uncheck Scrollview insets in storyboard

enter image description here

Upvotes: 0

Bhadresh Mulsaniya
Bhadresh Mulsaniya

Reputation: 2640

write this below line in your viewDidLoad method:

self.automaticallyAdjustsScrollViewInsets = false

Upvotes: 1

Related Questions