【问题标题】:Move Image In ScrollView along scrollbar沿滚动条在 ScrollView 中移动图像
【发布时间】:2016-01-08 05:53:27
【问题描述】:

我想在 scrollview 中沿滚动条移动 UIImageview 。我试过 DidScroll Delegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    static NSInteger previousPage = 0;
    NSLog(@"scrolliview= %f",scrollView.contentOffset.x);

   [_img_moving setBackgroundColor:[UIColor greenColor]];
    _img_moving.frame = CGRectMake(
                                 scrollView.contentOffset.x,
                                 0, 320/2, 10);

}

uiimageview 的框架没有改变。 注意:我的目标是制作宽度为 10 px 的绿色滚动条

【问题讨论】:

  • 你为滚动视图设置的 contentOffset 是什么?

标签: ios uiimageview scrollbar scrollview frame


【解决方案1】:

请尝试以下代码,根据需要更改垂直和水平滚动条的颜色,更详细的答案请点击此链接:
ios Changing UIScrollView scrollbar color to different colors

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //get refrence of vertical indicator
    UIImageView *verticalIndicator = ((UIImageView *)[scrollView.subviews objectAtIndex:(scrollView.subviews.count-1)]);
    //set color to vertical indicator
    [verticalIndicator setBackgroundColor:[UIColor greenColor]];


    //get refrence of horizontal indicator
    UIImageView *horizontalIndicator = ((UIImageView *)[scrollView.subviews objectAtIndex:(scrollView.subviews.count-2)]);
    //set color to horizontal indicator
    [horizontalIndicator setBackgroundColor:[UIColor redColor]];
}

【讨论】:

  • 兄弟,我已经尝试过那个链接但没有成功,它只是改变图像的颜色也没有移动图像,我想像滚动条一样移动图像
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-04
  • 2012-03-18
  • 2011-08-20
  • 1970-01-01
  • 1970-01-01
  • 2011-01-22
  • 1970-01-01
相关资源
最近更新 更多