Description:
we are adding custom UIView(have drawRect) inside the UIScrollView and its content size as more than 5500(width or height) then the UIScrollView behave strangely.
Note: if we remove the drawRect method then it will working fine.
Steps to Reproduce:
- Run the attached project
- See the reported issue
Expected Behavior:
- Subview of scroll view, draw method working
Actual Behavior:
- Subview of scroll view, draw method not working
Code Snippet :
- (void)viewDidLoad {
[super viewDidLoad];
//// create scroll view
UIScrollView* scrollView = [[UIScrollView alloc] init];
scrollView.backgroundColor = UIColor.redColor;
scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
scrollView.contentSize = CGSizeMake(6000, self.view.frame.size.height);
//// create custom view with drawRect method
CustomView* customView = [[CustomView alloc] initWithFrame:CGRectMake(0, 0, 6000, self.view.frame.size.height)];
//// add views to super view
[self.view addSubview:scrollView];
[scrollView addSubview:customView];
}
CustomView:
- (CustomView*)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if(self)
{
self.backgroundColor = UIColor.blueColor;
}
return self;
}
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 10);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextMoveToPoint(context, 0, self.frame.size.height / 2);
CGContextAddLineToPoint(context, self.frame.size.width, self.frame.size.height / 2);
CGContextStrokePath(context);
}
@end
Sample: https://drive.google.com/open?id=1446iyIvd4lax5p4s2TPAf5TEGdNYy3xg
Screen record: https://drive.google.com/open?id=1rxyUhdq66GjTHx_P2p-CYUL7LtqMTRGN