I have a UIScrollView with a very large content view, it's a bookshelf with around 1000 items on it, when the scroll views content becomes more than around 16000px high it shows a black background and all graphics overlap/blend together.
Here is the sample code
- (void)viewDidLoad {
[super viewDidLoad];
开发者_Python百科// Doesn't work
int sizeForContent = 20000;
// Does Work
//sizeForContent = 10000;
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, sizeForContent)];
subView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"wood.jpg"]];
[scroll addSubview:subView];
[subView release];
scroll.contentSize = CGSizeMake(self.view.frame.size.width, sizeForContent);
[self.view addSubview:scroll];
[scroll release];
}
Does anyone know why this happens? I assume it is something to do with memory limits but it doesn't seem to be using much memory.
I know I could set the scrollview background color directly instead of adding a subview and setting the background of that but I need to leave the scrollview background as a color.
You can get the basic xcode project from http://cl.ly/2i3F3q0G1j3q433n0f1E if you want to see the issue.
Any help or explanations greatly appreciated.
mhm, i also guess that it's a memory problem...
try to avoid this:
subView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"wood.jpg"]];
i suppose that when you do that xCode load a small jpg, but then draw it for the whole area of your UIView that at the and will have a big "image" to keep in memory...
try to use just a fill color instead and see if something change...
if so a possible solution could be to use a CATiledLayer for your view, so just the visible portion of your big UIView will be in memory (with the inconvenience that users will see it drawing everytime they scroll around...)
I also face the same problem. I have a long image, I just want to perform a panaroma effect on that while scrolling. If I used CATiledLayer, will it gives that smoothness. I dont think so will give that smoothness. Because it will draw everytime when it scrolls.I just want to do as the standard iPhone app icons scrolling the Home.
I solved it by creating view with pattern background, and adding scroll view as subview with [UIColor clearColor]
background.
精彩评论