我需要爲我的應用程序定製一個tab切換視圖,所以我使用UIScrollView和UITabBar創建了一個.xib。在更改UIScrollView的內容時保持滾動行爲和滾動條可見性
我添加了一個「ClearChildren」和「SwitchViews」方法將UIScrollView的是這樣的:
public static class Extensions
{
#region UIScrollView extensions
public static void ClearChildren (this UIScrollView scrollViewer)
{
foreach(var subview in scrollViewer.Subviews)
{
subview.RemoveFromSuperview();
}
}
/// <summary>
/// switches the content views of a UIScrollView entirely
/// with for example a tab-bar.
/// </summary>
/// <param name="scrollViewer">
/// A <see cref="UIScrollView"/>
/// </param>
/// <param name="newView">
/// A <see cref="UIView"/>
/// </param>
public static void SwitchViews (this UIScrollView scrollViewer, UIView newView)
{
scrollViewer.ClearChildren();
scrollViewer.AddSubview(newView);
//reset content size
scrollViewer.ContentSize = new System.Drawing.SizeF(newView.Bounds.Width, newView.Bounds.Height);
}
#endregion
}
然而
,當i開關上使用someUiScrollView.SwitchViews(someOtherScrollView)
一個UIScrollView的視圖的UIScrollView的突然失去其滾動條和允許水平和垂直滾動。
我該如何確保UIScrollView的水平和垂直滾動行爲不會改變,並保持滾動條可見?
很好的建議,但我把問題本身扼殺在萌芽狀態,這確實是我加載視圖的界限。它們比scrollviewer稍寬一點,然後它自動啓用水平滾動。 感謝您的時間和+1 – 2011-04-18 14:25:40