我創建一個應用程序,並在一個導航視圖中,我有一個非常類似的設計作爲App Store的應用程序 - 查看詳情|評論|相關章節。遵循類似的路線,我希望以蘋果公司在其應用程序中採用的「相同」方式實施細分控制。 (這也類似於Apple在默認iOS 7音樂應用程序中的「藝術家 - 相冊」導航視圖中的操作,儘管表格標題(也許)。)的iOS -Sticky分段控制像App Store應用
- 如果向上滾動,當分段控件容器觸摸導航欄,它粘在那裏。
- 它還允許用戶注意到,這是某種形式的疊加,由於與它相關的阿爾法。
- 向下滾動時,它會在需要時移動到位。
我做了什麼 -
我已經創建了分段控制的容器視圖。當scrollView滾動時,我重新定位我的容器視圖以完成粘性效果。這只是僞代碼,但我的代碼實際上工作。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView == self.labTestScrollView)
{
/*
As soon as the user scrolls up, y changes, therefore, we need to stick the options container view
such that it doesn't go past the UINavigationBar
Need to check if the origin of the options container view in the coordinate system of the main
superview is just gone past the UINavigationBar in this controller's view.
- get the bounds rect for the options container view
- convert these bounds and position them in the coordinates of this controller's view
- check if origin.x for container view is less than that of view.origin.y
- if less than stick it by converting the headerFrame to the coordinate system of the options
container view; and raise the stuck flag
- if greater, check if the stuck flag is raised; check for another object in space before the container view and adjust accordingly.
*/
}
}
這裏有兩個問題:
- 無疊加效應。我可以配置alpha,使效果更清晰一些,但這似乎並不自然。
- 第二個問題源於第一個問題。這似乎是一個非常具體的解決方案。我期待着更自然的事情;以及默認使用表格視圖或其他方法的東西。
好的,這種說法很有道理。 參考App Store應用程序,圖標,應用程序的名稱等位於Section 0中,並且沒有任何標題。 'UISegmentedControl'後的所有內容都在第1節中,'UISegmentedControl'是本節的標題。這是你說的嗎? – p0lAris
這是正確的。 *查看代碼示例的更新答案* – fguchelaar
好吧,這太好了。我明白你做了什麼。這幾乎是我正在尋找的。非常感謝! :) – p0lAris