简体   繁体   English

从UIViewController呈现半透明的UITableView

[英]Presenting a semi-transparent UITableView from a UIViewController

I'm working on an app that will rely on one main view controller with a row of buttons at the bottom to display other views with information. 我正在开发一个应用程序,该应用程序将依赖于一个主视图控制器,并在底部具有一行按钮来显示其他带有信息的视图。 From one of these buttons I want to present a tableview that presents a list of song titles. 从这些按钮之一中,我想呈现一个呈现歌曲名称列表的表格视图。 This app plays sound files, and I want the user to be able to tap a button, then select a song to be the default song to play. 该应用程序播放声音文件,我希望用户能够点击一个按钮,然后选择一首歌曲作为要播放的默认歌曲。 I want to present this tableview with a uiview animation, and I want it to be semi-transparent and only fill a portion of the screen. 我想用uiview动画呈现此tableview,并且我希望它是半透明的并且只填充屏幕的一部分。 I've tried creating a UITableViewController and then presenting it from the main view controller like so: 我试图创建一个UITableViewController,然后从主视图控制器中呈现它,如下所示:

UITableViewController *tableView = [[UITableViewController alloc]init];
[self presentViewController:tableView animated:YES completion:nil];

This presents a view controller that fills the entire screen though, which is not what I want. 这提供了一个视图控制器,尽管它占据了整个屏幕,但这不是我想要的。 And changing the view controller's frame at instantiation time doesn't seem to have an effect. 而且在实例化时更改视图控制器的框架似乎没有任何效果。 I can just animate a UITableView into the main view controller's view, but then I'm not so sure who is supposed to be the delegate and data source. 我可以将UITableView设置为主视图控制器的视图的动画,但是然后我不确定是谁作为委托和数据源。 Any suggestions? 有什么建议么? Thanks in advance. 提前致谢。

While adding table view as a subview, u can set its frame size or bound, and display it with animation whatever you like. 在将表格视图添加为子视图时,您可以设置其框架大小或边界,并根据需要随动画一起显示。 Yes, you can set delegate and datasource to self while adding . 是的,您可以在添加时将委托和数据源设置为self。

I use: (in viewDidLoad) 我使用:(在viewDidLoad中)

 self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.opaque = NO;

Then in cellForRowAtIndexPath: 然后在cellForRowAtIndexPath中:

cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [UIColor colorWithWhite:1 alpha:.55];

Not sure if this is what you wanted, but it gives you the option to make everything clear. 不知道这是否是您想要的,但是它为您提供了使所有内容清晰的选项。 (obviously the alpha would change for your case, but that measures the opacity of the cells) (显然,alpha值会因您的情况而改变,但这可以衡量单元的不透明度)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM