My question is about this method:
(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
I have read the documentation, but i don't understand what this method is for.
thanks for your answers.
My question is about this method:
(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
I have read the documentation, but i don't understand what this method is for.
thanks for your answers.
As mentioned in documentation.
Scrolling to a Specific Offset
Scrolling to a specific top-left location (the
contentOffset
property) can be accomplished in two ways. ThesetContentOffset:animated:
method scrolls the content to the specified content offset. If the animated parameter isYES
, the scrolling will animate from the current position to the specified position at a constant rate. If the animated parameter isNO
, the scrolling is immediate and no animation takes place. In both cases, the delegatesscrollViewDidScroll:
messages. If animation is disabled, or if you set the content offset by setting thecontentOffset
property directly, the delegate receives a singlescrollViewDidScroll:
message. If animation is enabled, then the delegate receives a series ofscrollViewDidScroll:
messages as the animation is in progress. When the animation is complete, the delegate receives ascrollViewDidEndScrollingAnimation:
message.i.e. In simple words if you want to scroll
UIScrollView
programatically by passing scrolling position values i.e. how much amount to scroll, you can use this method.This method also calls delegate
scrollViewDidScroll:
i.e. delegate method ofUIScrollView
class through which you can maintain the amount of scrolling ofUIScrollView
.UIScrollView lets you have content that is larger than what you can view on the screen. In the image below you can see a large red rectangle with a green rectangle inside.
The contentArea property of the UIScrollView defines the logical size of your view (the red rectangle). The visible area of the scroll view is represented by the green rectangle. The contentOffset is the upper left corner of the visible area. Changing contentOffset, the visible area will move around.
The method above will move the contentOffset (the upper left corner of the green rectangle) to a specified location, thus moving the visible area (the green rectangle).
Hope this helps.