简体   繁体   English

iOS如何在UITableViewController上向屏幕中心添加视图并将其粘贴到屏幕中心?

[英]iOS how to add a view to screen center and stick it to screen center on a UITableViewController?

I'm working on a UITableViewController . 我正在UITableViewController I have to display a view with some info, that view will be added to the TableViewController programatically. 我必须显示一个包含一些信息的view ,该视图将以编程方式添加到TableViewController This is my code of adding it: 这是我添加它的代码:

MyNotificationView *notificationView = // some initializations;
[self.view addSubview:notificationView]; // self is the UITableViewController
notificationView.center = self.view.center;

However on UITableViewController , this code actually sets the center of my notificationView to the center of the scrollable area of the TableViewController , and my notificationView scrolls as the TableView scrolls. 但是,在UITableViewController ,此代码实际上将我的notificationView的中心设置为TableViewController的可滚动区域的中心,并且我的notificationViewTableView滚动而滚动。 What I want is to add my notificationView to the screen center and stick it there, so how can this be done? 我想要的是将我的notificationView添加到屏幕中心并将其粘贴在屏幕中心,那么该怎么办呢?

您可以创建一个UIViewController,使其内部具有UITableView,并希望将其居中放置在NotificationView中,只需将其添加到视图[self.view addSubview:notificationView];

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

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