xcode Popover 和 tableview 透明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5503520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Popover and tableview transparent
提问by cyclingIsBetter
In my Ipad application I use a popover but I'm not able to make it transparent. The popover has a tableview inside; my code is:
在我的 Ipad 应用程序中,我使用了一个弹出框,但我无法使其透明。popover 里面有一个 tableview;我的代码是:
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(600, 800, 100, 100)];
popoverView.backgroundColor = [UIColor greenColor];
popoverContent.view = zoneViewController.view;
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[self.popoverController presentPopoverFromRect:CGRectMake(1200, -200, 50, 375) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:TRUE];
[[[popoverController contentViewController] view] setAlpha:0.25f];
I'm able to make transparent only the tableview, but popover remains black...why??
我只能使 tableview 透明,但 popover 仍然是黑色的......为什么?
采纳答案by Stephen Poletto
[[[popoverController contentViewController] view] setAlpha:0.25f];
This modifies the transparency of zoneViewController's view, which will be nested inside the Popover. However, there's currently no way for you to customize the appearance of the Popover itself. You can control the size and arrow direction, but not the border color or border transparency of the Popover.
这会修改 zoneViewController 视图的透明度,该视图将嵌套在 Popover 中。但是,目前您无法自定义 Popover 本身的外观。您可以控制大小和箭头方向,但不能控制 Popover 的边框颜色或边框透明度。
If you really want a transparent Popover frame, you'll have to write your own.
如果您真的想要一个透明的 Popover 框架,则必须自己编写。
回答by Deb Orton
I spent hours trying every solution listed on this site to get transparency to work on a UIPopoverController
containing a GROUPED UITableView
-- NONE of which worked for me:
我花了几个小时尝试这个网站上列出的每个解决方案,以获得透明度来处理UIPopoverController
包含 GROUPED 的工作UITableView
——没有一个对我有用:
- Put the popover in a parent view and change the alpha on THAT view. (FAILED)
- Change the alpha on various combinations of subviews (tableview background, tableview cells, popover background, etc.)
- Add background views to the cells and change the alpha on those. (FAILED)
- Finally: Change the alpha on EVERY view in the hierarchy starting from the popover content view (FAILED)
- 将弹出框放在父视图中并更改该视图上的 alpha。(失败的)
- 更改子视图(tableview 背景、tableview 单元格、popover 背景等)的各种组合的 alpha
- 为单元格添加背景视图并更改它们的 alpha。(失败的)
- 最后:从弹出内容视图(失败)开始更改层次结构中每个视图的 alpha
There's a black root view in the popover that has an alpha of 1.0 and it doesn't matter what you do with the subviews (or if you stick it in a superview), the transparency doesn't work. So, I crawled up the view hierarchy (by trial and error) until I got to that cursed black view and set ITS alpha explicitly. Success! All I had to add was one line of code AFTER the popover was visible:
弹出窗口中有一个黑色的根视图,其 alpha 为 1.0,无论您对子视图做什么(或者如果将其粘贴在超级视图中),透明度都不起作用。所以,我爬上视图层次结构(通过反复试验),直到我到达那个被诅咒的黑色视图并明确设置 ITS alpha。成功!在弹出窗口可见后,我只需要添加一行代码:
self.popoverController.contentViewController.view.superview.superview.superview.alpha = 0.5;
N.B. This solution will likely stop working when Apple makes updates to UIPopoverController
, so use at your own risk!
注意,当 Apple 对 进行更新时UIPopoverController
,此解决方案可能会停止工作,因此使用风险自负!
回答by Evgeny
Since iOS 5 you can set custom UIPopoverBackgroundView. Check the discussion at Customizing the UIPopoverController view background and border color
从 iOS 5 开始,您可以设置自定义 UIPopoverBackgroundView。查看自定义 UIPopoverController 视图背景和边框颜色中的讨论
回答by 0b10110
The popover is by default transparent. If you place subviews into the Popover view, then you must make the subviews' backgroundColor
transparent.
弹出框默认是透明的。如果将子视图放入 Popover 视图中,则必须使子视图backgroundColor
透明。
So, in your case, you will need to set the tableView's backgroundColor
property to [UIColor clearColor]
and you will also need to make your tableView cells transparent.
因此,在您的情况下,您需要将 tableView 的backgroundColor
属性设置为,[UIColor clearColor]
并且您还需要使 tableView 单元格透明。
Do not forget to make your cells transparent!
不要忘记让你的细胞透明!