How to place a graphic rectangle over a table in a UIView
I've got a UITableView which is shown in a UIView - the reason I've done this is that I want to place a solid rectangle over the table (with CGContextSetBlendMode kCGBlendModeMultiply) and continuously change its colour, so I get the effect of the table's text continuously changing colour. I can't think of any other way of doing this, but the problem I have is that the coloured rectangle always appears below the table and sits solidly on top of (or below if I change the order of the subviews) the other UIViews. It doesn't seem to have any effect on the table no matter what I do. Is there any way of changing the display order within the UIView? The table is connected from IB. I'm not s开发者_StackOverflow中文版ure what other info I need to post for anyone who might be able to answer! Thanks very much for any help.
In order to cover your TableView with another UIView, the covering UIView must have a sibling relationship with the TableView or with one of the ancestors of the TableView. If the TableView is "shown in a UIView", that UIView that it's shown in can never obscure the TableView. Child views always obscure parent views. Create another UIView inside the "shown in UIView", it will then be a sibling view to the TableView, and can be put on top of it. Like this:
UIView *parentView = [[UIView alloc] initWithFrame:parentFrame];
UITableView *tableView = [[UITableView alloc] // table create parameters....
[parentView addSubiew:tableView];
UIView *obscuringView = [[UIView alloc] initwithObscuringFrame];
[parentView addSubView:obscuringView];
The obscuring view will then sit on top of the table view.
精彩评论