Get current position of UIScrollView

I come with Android and I have a lot of headaches in iOS. I need to make the scroll menu like a movie. I used the following code:

rol = scroll_view.contentOffset.y; timer = [NSTimer scheduledTimerWithTimeInterval:.02 target:self selector:@selector(timer_rol) userInfo:nil repeats:YES]; -(void)timer_rol{ [scroll_view setContentOffset:CGPointMake(0,rol) animated:YES]; rol++; } 

This code works fine, but when the user interacts with scrolling up or down, the view returns to position up to (value rol). The question is, how can I get the current position of the content after scrolling

I already tried these codes, but no one works:

 CGPoint point = [scroll_view contentOffset]; rol = ry +1; -(void) handleGesture:(UIGestureRecognizer *) sender{} -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {} -(void)scrollViewDidScroll:(UIScrollView *)scrollView {} 

Can anybody help me?

+6
source share
3 answers

Decision:

 //Update the value of rol - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ rol_y = scroll_webView.contentOffset.y; rol_x = scroll_webView.contentOffset.x; } //Call the timer timer = [NSTimer scheduledTimerWithTimeInterval:.25 target:self selector:@selector(timer_rol) userInfo:nil repeats:YES]; //Scroll the view (Works when i set animated:NO) - (void)timer_rol{ [scroll_webView setContentOffset:CGPointMake(rol_x, rol_y + 1) animated:NO]; } 
+5
source

In timer_rol :

 [scroll_view setContentOffset: CGPointMake(0, scroll_view.contentOffset.y + 1) animated:YES]; 

Or, if you do not want the X-scroll to change,

 [scroll_view setContentOffset: CGPointMake(scroll_view.contentOffset.x, scroll_view.contentOffset.y + 1) animated:YES]; 
+6
source

Your timer will continue to work after scrolling, so you should probably call [timer invalidate]; when they start scrolling, and then initialize the timer again after stopping scrolling. (also set rol to new contentOffset )

+1
source

Source: https://habr.com/ru/post/974227/


All Articles