gpt4 book ai didi

ios - ScrollView 上绘制的线条不是滚动的?

转载 作者:行者123 更新时间:2023-11-29 11:00:10 25 4
gpt4 key购买 nike

在我的应用程序中,我将 UIScrollView 子类化并在 drawRect 方法中绘制水平线

我将 ContentSize 的高度设置为大于 scrollView 的高度。我用下面的方法画线

但我的问题是我画的线没有随 View 滚动。

-(id)initWithFFrame:(CGRect)rect
{
_gap=36;
}
- (void)drawRect:(CGRect)rect
{
// Drawing code
int end=0;
NSLog(@"called");
int x=self.frame.size.width;
while (end<self.contentSize.height) {
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 1);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextMoveToPoint(context, 0, end);
CGContextAddLineToPoint(context, x, end);
CGContextStrokePath(context);
end=end+_gap;
}
}

我可以注意到滚动条在滚动时上下移动,但线条没有移动。

最佳答案

问题是这些行是 UIScrollView 的一部分,而不是它的内容。

您需要创建一个新的 UIView 子类,在那里绘制内容,并将其添加到您的 UIScrollView

关于ios - ScrollView 上绘制的线条不是滚动的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16279761/

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