Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does contentOffset do in a UIScrollView?

What is the use of the contentOffset property in UIScrollView?

like image 824
Akash Avatar asked Jul 26 '10 23:07

Akash


People also ask

What is contentSize of Scrollview?

The content size of a scroll view doesn't change anything about the bounds of a scroll view and therefore does not impact how a scroll view composites its subviews. Instead, the content size defines the scrollable area. By default, a scroll view's content size is a big, fat {w:0, h:0} .

Which is a property of UIScrollView?

→ UIScrollView has 3 main properties, known as contentSize, contentOffset, and contentInset.

What is content size?

Most views have an intrinsic content size, which refers to the amount of space the view needs for its content to appear in an ideal state. For example, the intrinsic content size of a UILabel will be the size of the text it contains using whatever font you have configured it to use.

What is content insets in Swift?

Discussion. Use this property to extend the space between your content and the edges of the content view. The unit of size is points. The default value is UIEdgeInsetsZero . By default, UIKit automatically adjusts the content inset to account for overlapping bars.


2 Answers

It could be considered as the coordinate of the origin of scrollView's frame relative to the origin of its contentView's frame. See the picture below:

enter image description here

like image 147
Mehdi Ijadnazar Avatar answered Sep 23 '22 04:09

Mehdi Ijadnazar


According to the documentation, the contentOffset property represents:

The point at which the origin of the content view is offset from the origin of the scroll view.

In plain speak, it's how far the view has moved in each direction (vertical and horizontal). You can unpack vertical and horizontal distance by accessing the x and y properties of the CGPoint:

CGFloat xOffset = _myScrollView.contentOffset.x; CGFloat yOffset = _myScrollView.contentOffset.y; 
like image 33
Justin Avatar answered Sep 23 '22 04:09

Justin