Ipad 以图案图像为背景的UIScrollView
这是我面临的问题:我正在制作一个UIScrollView,它将有一个图案图像来填充背景。也就是说,我需要一个背景来使用UIScrollView滚动。iPad上的游戏中心应用程序就是一个很好的例子。背景将通过scrollview平滑滚动 目前我有两种方法来实现这种效果,但它们都没有提供良好的性能。 首先我试过这个Ipad 以图案图像为背景的UIScrollView,ipad,background,uiscrollview,Ipad,Background,Uiscrollview,这是我面临的问题:我正在制作一个UIScrollView,它将有一个图案图像来填充背景。也就是说,我需要一个背景来使用UIScrollView滚动。iPad上的游戏中心应用程序就是一个很好的例子。背景将通过scrollview平滑滚动 目前我有两种方法来实现这种效果,但它们都没有提供良好的性能。 首先我试过这个 self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:kRLCastViewBGUnit]]
self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:kRLCastViewBGUnit]];
但不幸的是,滚动性能非常差,占用了太多内存
然后我尝试在drawRect中使用CGContextDrawTileImage,如下所示:
- (void)drawRect:(CGRect)rect
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(currentContext, 0, rect.size.height);
CGContextScaleCTM(currentContext, 1.0, -1.0);
CGContextClipToRect(currentContext, rect);
CGRect centerTileRect = CenterTileRect;
CGContextDrawTiledImage(currentContext, centerTileRect, [ResourceProvider backgroundTileImageRef]);
}
在新的iPad上仍然不能令人满意。我一定是做错了什么,或者误用了一些方法,因为游戏中心在滚动时表现非常好。任何人都可以为我提供解决UIScrollView后台性能问题的解决方案吗?非常感谢 您应该改用UITableView。在这里,您可以轻松设置cell.backgroundView。
UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake:(0.0,0.0,320.0, height)];
backgroundView.image = [UIImage imageNamed:@"Shelf.jpeg"];
cell.backgroundView = backgroundView;
[scrollView setContentSize:CGSizeMake(320.0, 1000.0)];
[scrollView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellImage.png"]]];
如果您真的只想使用UIScrollView,则只获取一个单元格背景图像,图像宽度应与scrollView的宽度相同,因为colorWithPatternImage:方法的工作方式类似于平铺属性。
UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake:(0.0,0.0,320.0, height)];
backgroundView.image = [UIImage imageNamed:@"Shelf.jpeg"];
cell.backgroundView = backgroundView;
[scrollView setContentSize:CGSizeMake(320.0, 1000.0)];
[scrollView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellImage.png"]]];
仅将此图像带到项目中,并将其用作UIScrollView的背景色。
UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake:(0.0,0.0,320.0, height)];
backgroundView.image = [UIImage imageNamed:@"Shelf.jpeg"];
cell.backgroundView = backgroundView;
[scrollView setContentSize:CGSizeMake(320.0, 1000.0)];
[scrollView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellImage.png"]]];
这实际上是一个很好的问题,我也找不到解决办法。特别是在新的iPad上,性能非常糟糕。实际上,我最终手动处理了背景。我在UIScrollView中添加了两个UIImageView,并上下调整这两个背景,使其看起来像是有纹理的背景滚动。试着释放所有不再使用的变量和对象。。