我使用一個名爲SwiftyWalkthrough的外部庫,它允許我只顯示屏幕上的某些視圖,以指導新用戶通過我的應用程序的用戶界面。我想要暴露給用戶的第一個項目是UITabBarItem。我需要找到與特定UITabBarItem關聯的UIView。我知道該項目的索引,並且給它一個標籤。但我還沒有找到一種方法讓他們幫助我找到觀點。當然,我只想使用公共接口來實現這一點。如何找到特定UITabBarItem的UIView?
8
A
回答
19
我通過訪問tabBar的子視圖來解決我的問題。 userInteractionEnabled的視圖是UITabBarItems。通過minX值對它們進行排序可以確保它們與tabBar.items數組的順序相同。
extension UITabBarController {
func orderedTabBarItemViews() -> [UIView] {
let interactionViews = tabBar.subviews.filter({$0.isUserInteractionEnabled})
return interactionViews.sorted(by: {$0.frame.minX < $1.frame.minX})
}
}
+0
謝謝!真的很好,很優雅。我知道這可能會在未來破裂,但並不是一個更好的方法...... – elsurudo
1
測試中iOS10用Objective-C的:
[alert setModalPresentationStyle:UIModalPresentationPopover];
UIView *view = [self.tabBar.selectedItem valueForKey:@"view"];
alert.popoverPresentationController.delegate = self;
alert.popoverPresentationController.sourceView = self.tabBar;
alert.popoverPresentationController.sourceRect = view.frame;
alert.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionDown;
[self presentViewController:alert animated:YES completion:nil];
7
斯威夫特3版的卡爾 - 史密斯的答案
func orderedTabBarItemViews() -> [UIView] {
let interactionViews = tabBar.subviews.filter({$0.isUserInteractionEnabled})
return interactionViews.sorted(by: {$0.frame.minX < $1.frame.minX})
}
相關問題
- 1. 將UIView添加到UITabBarItem
- 2. 動態的UIView在UITabBaritem
- 3. 如何添加UITabBarItem到UITabBar
- 4. 在UIView中查找特定點
- 5. 如何找到特定的元標記
- 6. 如何找到特定的XSS孔?
- 7. 如何找到特定鍵的鍵碼
- 8. 如何找到特定的父節點?
- 9. 如何找到特定的xml節點?
- 10. 強制UITabBarItem的圖像到特定的大小
- 11. UITabBarItem selectedImageTintColor。如何找到設置爲tintcolor的顏色
- 12. 如何將UIGestureRecognizer限制到特定的UIView?
- 13. 我該如何確定UITabBarItem的位置?
- 14. 你如何自定義UITabBarItem的標題?
- 15. 的touchesBegan在特定的UIView
- 16. 如何找到特定區域在div
- 17. 當沒有self.view時,如何找到UIView?
- 18. UIView。如何快速找到Root SuperView?
- 19. 定製UITabBarItem
- 20. 自定義UITabBarItem
- 21. 如何限制觸摸事件到特定區域或UIView?
- 22. Java如何在特定字符串之後找到特定行?
- 23. 如何在特定範圍內找到特定值
- 24. 如何找到特定的詞在特里
- 25. 找到UITableView滾動的UIView
- 26. 無法找到「的UIView」
- 27. 如何定位UIView?
- 28. UIView renderInContex特定位置
- 29. 如何在Eclipse中找到定義特定類的插件
- 30. TYPO3擴展:如何找到特定的TS設定
有標籤欄項目很多意見。你在找哪一個? –
在屏幕底部的標籤欄上包含標題和圖標的人。我期望它是矩形的,高度與整個標籤欄相同,寬度等於標籤欄寬度除以標籤欄項目的數量。 –
我認爲沒有訪問UITabbaritem backgroundView,我們只能放置標籤欄項目的自定義圖像,但無法獲取tabbar項目的backgroundView。 –