获取UIScrollView的当前位置 [英] Get current position of UIScrollView
本文介绍了获取UIScrollView的当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我来自Android,而IOS令我头疼.我需要像电影学分一样制作滚动菜单.我使用下面的代码:
I'm coming from Android and i'm getting a lot of headache in IOS. I need to make a scroll menu like a movie credits. I used the code below:
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++;
}
此代码可以正常工作,但是当用户进行向上或向下滚动时,视图返回到之前的位置(rol值).问题是,滚动后如何获得当前内容的位置
This code works fine, but when the user interact scrolling up or down, the view return to position before (value of rol). The question is, how can i get the current content position after scrolling
我已经尝试过这些代码,但是没有人起作用:
i already tried these codes, but no one works:
CGPoint point = [scroll_view contentOffset];
rol = r.y +1;
-(void) handleGesture:(UIGestureRecognizer *) sender{}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {}
有人可以帮助我吗?
推荐答案
解决方案是:
//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];
}
这篇关于获取UIScrollView的当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文