UIScrollView contentOffset
@property(nonatomic) CGPoint contentOffset
Discussion of [UIScrollView contentOffset]
The default value is CGPointZero.
UIScrollView contentOffset example.
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;
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;
Example of [UIScrollView contentOffset].
NSLog(@"Offset : %@", NSStringFromCGPoint(scrollview.contentOffset.x));
or Define as like this
CGFloat offSet= scrollview.contentOffset.x;
NSLog(@"Offset : %f", offset);
or Define as like this
CGFloat offSet= scrollview.contentOffset.x;
NSLog(@"Offset : %f", offset);
UIScrollView contentOffset example.
print the Logs for offset being set in scrollViewDidScroll: method.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@" Offset = %@ ",NSStringFromCGPoint(scrollView.contentOffset));
}
This will help you identify the offset values being set (in most cases, the required offset is overriden by another call to setContentOffset: , some where in the code; lets say the current offset is (130,0) and you want to set the offset (300,0) it happens in steps (if animated) , you might get logs like
Offset = {130,0}
Offset = {190,0}
Offset = {220,0}
Offset = {270,0}
Offset = {300,0}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@" Offset = %@ ",NSStringFromCGPoint(scrollView.contentOffset));
}
This will help you identify the offset values being set (in most cases, the required offset is overriden by another call to setContentOffset: , some where in the code; lets say the current offset is (130,0) and you want to set the offset (300,0) it happens in steps (if animated) , you might get logs like
Offset = {130,0}
Offset = {190,0}
Offset = {220,0}
Offset = {270,0}
Offset = {300,0}