为啥程序背景会减慢 UIScrollView?
Posted
技术标签:
【中文标题】为啥程序背景会减慢 UIScrollView?【英文标题】:Why does procedural background slow down UIScrollView?为什么程序背景会减慢 UIScrollView? 【发布时间】:2013-08-17 05:32:13 【问题描述】:我的问题代码在我在 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];
【问题讨论】:
【参考方案1】:可能是因为您超出了滚动范围。尝试:
[yourScrollView setContentOffest:CGPointMake(0,0)];
【讨论】:
以上是关于为啥程序背景会减慢 UIScrollView?的主要内容,如果未能解决你的问题,请参考以下文章