好的,我已经在互联网上到处寻找答案,我正在尝试创建一个自定义的UIScrollView滚动条。
这里是滚动条图片的链接
http://postimage.org/image/cg2jvde9z/
http://postimage.org/image/ko0mp3kdj/ (那个白色的框只是为了测试滚动视图)
我已经让滚动条工作了,尽管我需要帮助来确定每次按下滚动条时滚动视图应该移动多少像素。
这里有一些代码
-(IBAction)scroller_bar:(id)sender withEvent:(UIEvent *)event{
UIButton *button_sent = (UIButton *)sender;
UITouch *touch = [[event touchesForView:button_sent] anyObject];
CGPoint previousLocation = [touch previousLocationInView:button_sent];
CGPoint location = [touch locationInView:button_sent];
CGFloat delta_x = location.x - previousLocation.x;
float left_side = button_sent.center.x + delta_x;
float right_side = button_sent.center.x + delta_x;
if (right_side > button_sent.center.x) {
scroll_right = YES;
}
else{
scroll_right = NO;
}
if (left_side <= 13 + 50.5 || right_side >= 307 - 50.5) {
}
else{
button_sent.center = CGPointMake(button_sent.center.x + delta_x,
button_sent.center.y);
if (scroll_right) {
[selection_scroll setContentOffset:CGPointMake(selection_scroll.contentOffset.x - (Help HERE!), selection_scroll.contentOffset.y) animated:YES];
}
else{
[selection_scroll setContentOffset:CGPointMake(selection_scroll.contentOffset.x + (Help HERE!), selection_scroll.contentOffset.y) animated:YES];
}
}
}
在上面的代码中,您应该看到一个“(帮助此处!)”,这是我试图弄清楚滚动视图应向右移动多少像素的地方。这是一个有点令人困惑的问题,希望您能理解。谢谢 :)