Navigationbar resets content offset after taping back button - scroll

I have a bunch of scrolling views displayed by Navigationbar.PushViewController(...). When I show them these controls have their contentOffset set. The problem is that after tapping a back button in the navigationbar this offset is changed to Point 0,0 and after that it goes to the correct value. The setting to 0,0 causes my controls to load data while not required (offset was not changed by user). How can I avoid this 'temporary reset'of the offset?

Have you tried storing the contentOffset in a variable in ViewWillDisappear? Then resetting contentOffset in ViewDidAppear?
I think the contentOffset functionality you are experiencing is a feature (ha ha) of UIKit.

Related

A control in NSTableCellView is being moved to right automatically after resizing or scrolling

I'm trying to implement a counter view that shows items count in NSTableCellView.
The weird thing is it gets moved to right automatically after resizing window or scrolling the NSOutlineView which has the NSTableCellView.
Here is some screenshots of it. You will be able to see the counter view which shows "42" being moved to right after resize the window.
Following is the init state of the counter view.
Following is the state after resize window.
Following is difference between init position and the position after resize window.
Cell Autoresize Property
Count Button Autoresize Property
I'm guessing this is related to scrollview but I was not able to find more clues about this issue. BTW, official Mail App on Mac works as same with this but the difference is the counter of the Mail app is being changed right after launch so it does not being moved after resize window.
Anybody knows about this? Any thoughts would be appreciated.
Here is a link that allows you to download the sample project that apple provides and you can reproduce what I'm facing.
Sidebar Demo App that providing by Apple.
You just need to change Deployment target before you run it from Project -> Targets -> Deployment Info section.
If I interpret the autoresizing screenshots correctly, the '42' control is behaving as specified. You've pinned the right side of the '42' counter to right side of the cell. And that is where it stays, glued to the right side of the cell.
The cell is pinned to the left side of the tableview and that is where it stays, glued to the left side of the tableview. You have not pinned the right side of the cell to anything and so when you resize, the right side goes where it pleases, only maintaining the specified width of the cell. If you want to glue the right side of the cell to the width of the tableView or column (not sure which it is), pin it. Do specify a minimum width for the cell. If you don't specify a maximum width, or fixed width, the cell will stretch and shrink with resizing. If you fix the width, only the right view or column will stretch.

Slider inside Horizontal scroll view issue in IOS

My layout has severalsliders in a scroll view which scrolls horizontally. The issue is when I try to drag the slider thumb it is not moving instead the scroll view itself scrolls horizontally. How to fix this? (In Swift)
Swift 3 Solution
I was facing a similar issue and fixed it by setting
scrollView.delaysContentTouches = false
Explanation
According to Apple Docs
If the value of this property (delaysContentTouches) is true, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. If the value is false , the scroll view immediately calls touchesShouldBegin(_:with:in:)
. The default value is true.
As the word suggests it delays the content touch (i.e lowers the priority of subview's action) leading to irresponsive subview content updation during scrolling.
When this property is set to false it gives priority to the subview's action (by immediately calling touchesShouldBegin(_:with:in:)) leading to responsive subview content updation.
Maybe you call UISlider "Lazy var". Let's change it to "Let"

Explicit layout margins defined in storyboard are discarded at runtime

In my storyboard, I set the layout margins on my view to Explicit, with a 30 value for the left.
Everything looks fine in the storyboard editor view:
... but when I launch my app, the layout margins go back to the default (8,8,8,8):
Attempting to read the value programmatically (myView.layoutMargins) shows that default value again. It's as though no matter what value I set in the layout margins, it does absolutely nothing at run time.
To reproduce:
Create a new view controller in IB.
Add a view and set the layout margins to explicit (30,8,8,8)
Create a top, left, width, and height constraints for the view.
Give the view a background color so it's easy to tell if the label is indented correctly or not.
Add a label as a subview of that view and pin it to the top and left margins.
Notice how in the storyboard, the label is indented by 30 pixels from the left.
Run the app. Notice how the label loses its 30 pixel indentation and instead restores back to the default 8 pixel.
Note: I'm using Xcode 7.
Look like it's fixed in Xcode 8.
However, if you try reading the layoutMargins value in viewDidLoad it won't report the value set in the storyboard. You have to wait until a later method is called such as viewDidAppear to see the correct value.

UIScrollView contentInset is set to nonZero when using autolayout

So I have the following view hierarchy :
A full size scrollView in my viewController's view with the following constraints :
These are the constraints on containerView (ignore the second last one, its a hacky semi-fix for my problem):
I have the status bar, the navigation bar and the tab bar visible.
The thing is that when I set a breakpoint to check the scrollView's contentInset, it shows 64 on top and 49 on bottom, left and right are zero.
There is no way to set contentInset in IB, I tried setting it in an IBAction to UIEdgeInsetZeio, but that didn't fix it either. This is screwing up my scrollview by adding space above and below my contentView, how can I fix this?
By default the view controller extends the view under the top navigation bar so your content will blur under a translucent navigation bar. This is controlled by edgesForExtendLayout which is managed in Storyboard via the Extend Edges setting.
By default, the scrollview will automatically adjust its content inset so the content appears below the top layout guide. This is controlled by automaticallyAdjustsScrollViewInsets which is also managed in Storyboard.
What you did was constrain the top of your scroll view to the top layout guide instead of the top of its superview. By doing this, you manually offset it by 64 points. However, the scrollview is still automatically insetting its content by 64 points, which is why you're seeing additional space above and below your scroll view.
Either constrain your scrollview to its superview (so its content scrolls under the top/bottom bars), or disable the view controller from automatically adjusting the scroll view inset.

Push segue to scrollview display error

maybe this is a rather simple question. I don't know. I searched the forums for an answer but couldn't find one. I have two views. From a tablecell I push to a second view which contains a scrollview (960 x 455). This scrollview is centered when loaded.
Whenever I push into this view, the left part of the scroll which shouldn't be visible right away shows up for a few seconds. The same happens when I push back. Is there a way to push into the second view and only show the center of the scrollview?
I would have thought that this is occurring because the view is being loaded and then afterwards the position is being set which can take a while when the view is first being loaded as their other things being processed before setting the position.
I am presuming you are using interface builder if so I recommend setting the UIScrollViews visible/hidden property to true in there then in the viewDidLoad method setting it's position to centre after which you can set it to be visible again.

Resources