I have a UIScrollView
with an image that needs to be scalable. I want to have a "footer" with a black (opaque) background and white text. I wanted to have it be fixed as a footer. It will be opaque so you can see the image behind it.
I created a containing UIView
for the scrollview and footer. I can get the scrollview to be smaller than the app frame and have a footer at the bottom filling in the extra space, but obviously I can't see the image behind the footer.
I also tried putting the UIScrollView
and UIView
(footer) inside the container and positioning them accordingly, but in this case I can't even see the footer. Any ideas?
Code I've gotten so far (executed in viewDidLoad
of view controller):
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
UIView* view = [[UIView alloc] initWithFrame:appFrame];
view.backgroundColor = [UIColor blackColor];
CGRect scrollViewFrame = CGRectMake(0.0, 0.0, view.frame.size.width, view.frame.size.height - 100);
UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
[scrollView setCanCancelContentTouches:NO];
scrollView.clipsToBounds = YES;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
[scrollView addSubview:image开发者_如何学GoView];
[scrollView setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
scrollView.minimumZoomScale = 0.7;
scrollView.maximumZoomScale = 5;
scrollView.delegate = self;
[scrollView setScrollEnabled:YES];
UIView* textView = [[UIView alloc] initWithFrame:CGRectMake(0.0, scrollViewFrame.size.height, appFrame.size.width, 100)];
// Red for testing purposes
textView.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.5];
[view addSubview:scrollView];
[view addSubview:textView];
self.view = view;
I assume that with "image" you mean that there is an UIImage
in the scroll view, and that you want to see it through a half transparent footer view.
In this case you should not put the views beneath each other, but the footer view on top of the scroll view. You can insure it is on top by calling bringSubviewToFront
or using [containerView insertSubview:footer atIndex:0];
instead of addSubview:
.
Another caveat might be that you call your view view
. There might be some unpredictable behavior about which view it is, so perhaps it is better to call it something else and then assign it to self.view
.
I have plenty of UIScrollViews with a small non-scroll view at the bottom or the top. In most cases I don't have any overlap, and they just sit side-by-side. I create them all in InterfaceBuilder, and assign them to IBOutlets.
精彩评论