Very strange behaviour from UIScrollView. Kindly check the following code
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scrView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
scrView.delegate =self;
[scrView setContentSize:CGSizeMake(95000, self.view.bounds.size.height)];
scrView.backgroundColor = [UIColor clearColor];
Testview *test = [[Testview alloc]initWithFrame:CGRectMake(0, 0, scrView.contentSize.width, self.view.bounds.size.height)];
test.backgroundColor = [UIColor greenColor];
[scrView addSubview:test];
[scrView flashScrollIndicators];
[self.view addSubview:scrView];
self.view.backgroundColor = [UIColor clearColor];
}
Testview is a subview of Scrollview.
@implementation Testview
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
}
In Testview class, if I call the method - (void)drawRect:(CGRect)rect, Uiscrollview goes blank and unable to view the scrollview in runtime. But if I comment drawRect method
@implementation Testview
//- (void)drawRect:(CGRect)rect {
//
// [super drawRect:rect];
//}
it works perfect.I am breaking my head to solve this, please help me out to solve this issue. I need drawRect to work if the content size width and subview width are more than 95000.
-drawRect
with such a large canvas. (95000x640). I guess you're probably running out of memory, but you don't give any reason for your suspicion that UIScrollView is deallocated. That's probably not what's happening. What does the debugger and crash logs tell you? - nielsbot-[UIScrollView dealloc]
- nielsbotCATiledLayer
. (Override+layerClass
inTestview
to return[ CATiledLayer class ]
) - nielsbot