UIScrollView with background image

2019-05-06 18:04发布

问题:

I want to have a background image behind a UIScrollView area. That part's easy. The issue I'm running into is I don't want the image to move. I want it to fill the screen and then the scrolling just happens over that without effecting the image in anyway.

I've looked through lots of other postings on similar topics, but can't seem to get anything to work.

When I do the following, the background scrolls:

CGRect fullScreenRect = [[UIScreen mainScreen] applicationFrame];
UISCrollView *scrollView = [[UIScrollView alloc] initWithFrame:fullScreenRect];
scrollView.backgroundColor = [UIColor clearColor];
UIImageView *bkg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img"]];
[scrollView addSubview:bkg];

回答1:

Put the image in a UIImageView and place it behind the UIScrollView. Set the UIScrollView's color to 100% transparency ([UIColor clearColor]).