我使用一個名爲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中查找特定點
- 2. 如何添加UITabBarItem到UITabBar
- 3. 如何找到特定的XSS孔?
- 4. 如何找到特定的xml節點?
- 5. 如何找到特定鍵的鍵碼
- 6. 如何找到特定的元標記
- 7. 如何將UIGestureRecognizer限制到特定的UIView?
- 8. 你如何自定義UITabBarItem的標題?
- 9. 我該如何確定UITabBarItem的位置?
- 10. 的touchesBegan在特定的UIView
- 11. UIView。如何快速找到Root SuperView?
- 12. 當沒有self.view時,如何找到UIView?
- 13. 定製UITabBarItem
- 14. 自定義UITabBarItem
- 15. Java如何在特定字符串之後找到特定行?
- 16. 找到UITableView滾動的UIView
- 17. 無法找到「的UIView」
- 18. 如何定位UIView?
- 19. UIView renderInContex特定位置
- 20. 如何找到鏈接到特定長URL的縮短網址?
- 21. 如何找到鏈接到某個特定頁面的網頁?
- 22. 如何找到一個特定的類,並找到一個特定的元素,並添加禁用attr
- 23. 如何找到,如果鼠標移到在特定幀
- 24. UITabBar和UITabBarItem與特定的圖像@ 2x的iPhone 5和iPhone 6
- 25. 找到,並在特定塊
- 26. 如何找到特定的JSON文檔的CouchDB的
- 27. 如何使推送通知打開特定的uiview
- 28. 如何將特定的ViewController分配給UIView(在UICollectionView中)?
- 29. 如何反轉UIView特定區域的顏色?
- 30. 如何刪除一個UITabBarItem
有標籤欄項目很多意見。你在找哪一個? –
在屏幕底部的標籤欄上包含標題和圖標的人。我期望它是矩形的,高度與整個標籤欄相同,寬度等於標籤欄寬度除以標籤欄項目的數量。 –
我認爲沒有訪問UITabbaritem backgroundView,我們只能放置標籤欄項目的自定義圖像,但無法獲取tabbar項目的backgroundView。 –