获取UIScrollView的当前位置

Raf*_*dão 8 position objective-c uiscrollview ios contentoffset

我来自Android,我在IOS中遇到了很多麻烦.我需要像电影一样制作滚动菜单.我使用下面的代码:

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++;
}
Run Code Online (Sandbox Code Playgroud)

此代码工作正常,但当用户交互向上或向下滚动时,视图返回到之前的位置(rol的值).问题是,如何在滚动后获得当前内容位置

我已经尝试过这些代码,但没有人工作:

CGPoint point = [scroll_view contentOffset];
rol = r.y  +1;

-(void) handleGesture:(UIGestureRecognizer *) sender{}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {}
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?

Gut*_*der 8

timer_rol:

[scroll_view setContentOffset:
    CGPointMake(0, scroll_view.contentOffset.y + 1) 
    animated:YES];
Run Code Online (Sandbox Code Playgroud)

或者,如果您不希望X滚动更改,

[scroll_view setContentOffset:
    CGPointMake(scroll_view.contentOffset.x, scroll_view.contentOffset.y + 1) 
    animated:YES];
Run Code Online (Sandbox Code Playgroud)


Raf*_*dão 5

解决方案是:

//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];
}
Run Code Online (Sandbox Code Playgroud)