为什么程序背景会降低UIScrollView的速度?

时间:2013-08-17 05:32:13

标签: iphone ios uiview uiscrollview drawrect

我的问题代码是在程序背景中,我在UIView(drawRect :)中绘制,然后我将其添加为UIScrollView的子视图。程序代码如下。它绘制了盒子形状,看起来有点像天际线。任何想法为什么这会减慢我的UIScrollView?它似乎只在第一个卷轴上很慢,然后就好像它被缓存一样。背景可以有时多达一千个像素宽或更多。见图像......

- (void)drawRect:(CGRect)rect
{
UIBezierPath *vertLine = [[UIBezierPath alloc] init];

[vertLine moveToPoint:CGPointMake(0,self.frame.size.height)];

int detail = 10;
int ranNum = 0;
int count = self.bounds.size.width/detail;
CGFloat heightIncrement = 0.0;

CGFloat minHeight = self.frame.size.height;

CGFloat xPos = 0;
CGFloat yPos = self.frame.size.height-20;

for (int i =0; i<count; i++)
{
    ranNum += (arc4random() % 9)-5;

    yPos -= (arc4random() % 30);
    [vertLine addLineToPoint:CGPointMake(xPos,yPos)];

    xPos += (arc4random() % 20)+10;
    [vertLine addLineToPoint:CGPointMake(xPos,yPos)];

    yPos += (arc4random() % 30);
    [vertLine addLineToPoint:CGPointMake(xPos,yPos)];

    xPos += (arc4random() % 30);
    [vertLine addLineToPoint:CGPointMake(xPos,yPos)];

    if (yPos>self.frame.size.height-10) {
        yPos = self.frame.size.height-10;
    }

    if (yPos<self.frame.size.height-50) {
        yPos = self.frame.size.height-50;
    }

}

[vertLine addLineToPoint:CGPointMake(count*20,(self.frame.size.height))];

[[UIColor colorWithRed:0.0/255.0 green:38.0/255.0 blue:51.0/255 alpha:1] setFill];

[vertLine fill];

}

enter image description here

1 个答案:

答案 0 :(得分:0)

可能是因为你抽出了滚动界限。尝试:

[yourScrollView setContentOffest:CGPointMake(0,0)];