[英]iOS 7 Custom TableView Is Under TabBar
我嘗試將我的應用程序iOS7
到iOS7
,但我的自定義TableViewController
顯示TabBar
下的最后一行(單元格):(
我正在尋找它,但我沒有找到任何解決方案。 誰能幫我?
該錯誤顯示在打擊屏幕截圖中(僅顯示最后一個產品的一部分,因為我正在向上展示以顯示標簽欄下的隱藏產品):
謝謝。
我有同樣的問題,並使用故事板解決了它。 在Tab Bar Controller中,轉到屬性檢查器,Simulated Metrics,然后將Bottom Bar設置為Opaque Tab Bar。 而已! 有關說明,請參見下圖。
Saudações! (問候!)
我在另一篇文章中找到了你的問題的答案,由dariaa回答,在這里:
它對我很有用。
請不要相信我,因為我不是解決它的原始人。
在自定義TableViewController中,在[super viewDidLoad]下添加這兩行:
- (void)viewDidLoad
{
[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeAll;
self.tableView.contentInset = UIEdgeInsetsMake(0., 0., CGRectGetHeight(self.tabBarController.tabBar.frame), 0);
}
我的朋友們,我不能告訴你我是多么掙扎。 沒有一個故事板的重新配置從來沒有幫助過我。 問題與原帖一樣,我已設法使用以下方法修復它:
對於斯威夫特3
self.edgesForExtendedLayout = []
對於objective-c
self.edgesForExtendedLayout = NO;
viewDidLoad
2行,就是這樣!
self.edgesForExtendedLayout = UIRectEdgeAll;
self.tableview.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, CGRectGetHeight(self.tabBarController.tabBar.frame), 0.0f);
在iOS 7中,viewController使用全高。 有一個屬性介紹為
self.automaticallyAdjustsScrollViewInsets = NO;
把它設為否。 然后檢查,或設置UIEdgeInset如果沒有在它之后設置。
UIEdgeInsetsMake(top, left, bottom, right)
編輯 :也嘗試這個
self.edgesForExtendedLayout = UIRectEdgeNone;
此問題的根本原因是automaticallyAdjustsScrollViewInsets
僅在 VC的視圖層次結構中的第一個滾動視圖上有效 。 Apple沒有記錄它,但它是VC檢測需要修改的滾動視圖的唯一方法,除非您使用的是UITableViewController。
因此,為了在不手動調整insets的情況下修復問題,請執行以下操作:
UIViewController有兩個新屬性可以幫助您: topLayoutGuide
和bottomLayoutGuide
。 它們返回您需要避免的父視圖控制器控件的高度。 在這種情況下, bottomLayoutGuide
將返回標簽欄的偏移量。
您的自定義視圖控制器可能會覆蓋一個方法,而不是調用super
的實現,而這將為您完成。 我猜您正在安裝AutoLayout約束或手動設置視圖的框架以填充視圖。 您只需要將[bottomLayoutGuide length]
的值包含在布局計算中。 如果您支持旋轉,則應在willAnimateRotationToInterfaceOrientation:duration:
更新該值willAnimateRotationToInterfaceOrientation:duration:
.
UINavigationController
和UITabBarController
都有一個透明標志,可以通過編程或故事板設置。
UINavigationController
還有兩個標志,用於控制內容是在頂部或底部欄下延伸。 您可以再次以編程方式或在故事板中設置它們。 這將適用於所有子視圖。
每個UIViewController
都可以在代碼中設置自己的首選項。 該屬性稱為edgesForExtendedLayout
,您可以設置所有組合。
使用這些屬性將允許AutoLayout和Springs'n'Struts以您希望的方式調整視圖,而不管設備如何。
UIViewController
中有許多新屬性,您需要查看它們。
請嘗試以下方法:
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeBottom;
使用以下方法掩蓋了問題:
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 112, 0);
}
但它沒有解決,因為在每個iPhone和每個app tableview上我底部有不同的空間。
所以這是一個糟糕的解決方案。
我不知道解決它的方法。
我現在解決了我的問題,將我的BaseTableViewController更改為從UIViewController繼承到UITableViewController。
但是在UIViewController中使用TableView並沒有解決:(
謝謝。
也許不是一個正確的答案,也是因為這個原因我發布這個答案,所以你可以告訴我這個答案是否可能是一個可能的解決方案。
在我的情況下,我喜歡半透明效果,所以我在表格中添加了一個頁腳,我修改了scrollIndicators。
- (void)viewDidLoad
{
// Do any additional setup after loading the view.
[super viewDidLoad];
UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.agendaItemsTable.frame.size.width, self.tabBarController.tabBar.frame.size.height)];
self.agendaItemsTable.tableFooterView = footer;
self.agendaItemsTable.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, self.tabBarController.tabBar.frame.size.height, 0);
}
你怎么看?
我遇到了同樣的問題,而且投票的答案並沒有解決。 請參閱我對類似問題的回答, Tab Bar涵蓋了iOS7中的TableView單元格 。
我通過在表視圖控制器的viewWillAppear:
方法中手動設置表視圖的框架到屏幕高度來解決問題 - (狀態欄高度+導航欄高度+標簽欄高度)。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Adjust height of tableview (does not resize correctly in iOS 7)
CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.size.height = [self heightForTableView];
self.tableView.frame = tableViewFrame;
}
- (CGFloat)heightForTableView
{
return CGRectGetHeight([[UIScreen mainScreen] bounds]) -
(CGRectGetHeight([[UIApplication sharedApplication] statusBarFrame]) +
CGRectGetHeight(self.navigationController.navigationBar.frame) +
CGRectGetHeight(self.tabBarController.tabBar.frame));
}
如果有人找到更好的解決方案,請分享!
對於喜歡半透明效果的xarly和Autolayout解決方案(沒有設置框架)的人,請參閱我的答案https://stackoverflow.com/a/26419986/1158074
我對集合視圖有類似的問題。 更改集合視圖框架和內容插入下面為我修復它...
guard let cv = collectionView,
let tabBar = tabBarController?.tabBar else { return }
// Resize collection view for tab bar
let adjustedFrame = CGRect(origin: cv.frame.origin,
size: CGSize(width: cv.frame.width, height: cv.frame.height - tabBar.frame.height))
cv.frame = adjustedFrame
// Adjust content inset for tab bar
let adjustedContentInsets = UIEdgeInsetsMake(0, 0, tabBar.frame.height, 0)
cv.contentInset = adjustedContentInsets
cv.scrollIndicatorInsets = adjustedContentInsets
祝好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.