iPhone: Overlaying image over UIScrollView or UITableView
See this screenshot of the On The Day app.
At the bottom of the app the last entry is faded and the text is drawn underneath the custom graphic of an old page curl. I'm pretty sure it's because the view is being drawn below an image with transparency.
How am I able to overlay an image on top of a UIScrollView or UITableView such that I can get this kind of effect, but touch events are still handled by th开发者_运维技巧e underlying view?
All you need to do is drop an image view above the scroll view or table view. In Interface Builder, simply size and position the image view on the region where you want it to fade your scroll view. Or, in code:
UIImageView *overlayView = [[UIImageView alloc] initWithImage:someImage];
[overlayView setFrame:someFrame];
// Your scroll view or table view would be a subview of this view
[viewContainingScrollView addSubview:overlayView];
[viewContainingScrollView bringSubviewToFront:overlayView];
[overlayView release];
The image view will ignore touches by default, thus passing the touches to the next view in the responder chain. This allows your scroll view or table view to pick up the touches in the area occupied by the image view, without you having to write any more code.
If you really want to make sure, though, you simply need to disable user interaction on the image view:
[overlayView setUserInteractionEnabled:NO];
精彩评论