我們將顯示帶有標籤在一個表視圖中呈矩形,當我們遇到一個錯誤:的iOS:視定位甩出的熱點指標
有了這個代碼:
// Fix location of message bar even as user scrolls table - per http://stackoverflow.com/q/7537858/47281
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
let newY = self.tableView.contentOffset.y + self.navigationController!.navigationBar.frame.size.height + UIApplication.shared.statusBarFrame.height
// Show rectangle using 0 and newY ...
它運行良好,但在某些情況下無法正常工作,例如啓用Personal Hotspot時。還有就是導航欄和狀態矩形之間的間隙:
什麼是始終定位導航欄下一些正確的方法是什麼?
在第一種情況下,狀態欄高度爲20,但在第二種情況下爲40.在這兩種情況下,導航欄和內容偏移量都是相同的。即:
- 情況#1:膠印:-64.0,導航欄高度:44.0狀態欄高度:20.0
- 情況#2:偏移:-64.0,導航欄高度:44.0狀態欄高度:40.0
好像偏移不會因狀態欄中的高度變化而增加。
更新:請參閱(我的)接受的答案。我確信有更好的方法..如果你知道一個,請添加到線程。
set'definePresentationContext = true' –