gpt4 book ai didi

iphone - 创建自定义 UIScrollView 滚动器

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:25:12 26 4
gpt4 key购买 nike

好吧,我一直在网上寻找这个问题的答案,我正在尝试创建一个自定义的 UIScrollView 滚动条。

这是滚动条图片的链接

http://postimage.org/image/cg2jvde9z/

http://postimage.org/image/ko0mp3kdj/(那个白框只是为了我测试scrollview)

我已经让滚动条工作了,尽管我需要帮助来确定每次按下滚动条时 ScrollView 应该移动多少像素

这是一些代码

-(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];


}
}

在上面的代码中,您应该会看到一个“(Help HERE!)”,

这就是我试图弄清楚我应该将 ScrollView 移动多少像素的地方。这是一个有点令人困惑的问题,希望你能理解。

谢谢 :)

最佳答案

我不知道 APPLE 是否会批准这个但是下面写的代码可以改变 scollView 的滚动图像

for (UIImageView *img in yourscrollView.subviews) { 
[img setImage:[UIImage imageNamed:@"your custom scroller image"]];
}

关于iphone - 创建自定义 UIScrollView 滚动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11028355/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com