我有一個視圖有4個文本框和頂部的標誌 - 當用戶輸入信息的文本墊掩蓋了一些這些控制,我怎樣才能使視圖滾動,這樣不是問題。Monotouch - 使UIView可滾動
我曾嘗試將視圖添加到UIScrollView
,但似乎沒有做任何事情?
我有一個視圖有4個文本框和頂部的標誌 - 當用戶輸入信息的文本墊掩蓋了一些這些控制,我怎樣才能使視圖滾動,這樣不是問題。Monotouch - 使UIView可滾動
我曾嘗試將視圖添加到UIScrollView
,但似乎沒有做任何事情?
我已經包含了如何處理您的情況的snippit。如果我正確地理解了你的話,你不希望有一個可滾動的視圖,而是希望視圖與切換字段切換一起移動以減輕鍵盤造成的視覺障礙。
Goodluck!
private void ScrollTheView(bool movedUp, float scrollamount, UIView ViewToMove)
{
//To invoke a views built-in animation behaviour,
//you create an animation block and
//set the duration of the move...
//Set the display scroll animation and duration...
UIView.BeginAnimations(string.Empty, System.IntPtr.Zero);
UIView.SetAnimationDuration(0.15);
//Get Display size...
RectangleF frame = ViewToMove.Frame;
if (movedUp) {
//If the view should be moved up,
//subtract the keyboard height from the display...
frame.Y -= scrollamount;
}
else {
//If the view shouldn't be moved up, restore it
//by adding the keyboard height back to the original...
frame.Y += scrollamount;
}
//Assign the new frame to the view...
ViewToMove.Frame = frame;
//Tell the view that your all done with setting
//the animation parameters, and it should
//start the animation...
UIView.CommitAnimations();
}
您需要設置更多的UIScrollView,而不僅僅是將子視圖放在裏面。爲子視圖的完整大小正確設置ContentSize屬性,以便滾動視圖瞭解其中較大的內容,而不是控制滾動位置,縮放因子等等。
iOS SDK上有很多示例,只需檢查UIScrollView文檔,從ObjectiveC轉換爲Monotouch很簡單,或者查看http://blog.touch4apps.com/home/iphone-monotouch-development/monotouch-infinite-loop-image-scroll-view的博客文章,我在UIScrollView中有自動滾動的圖像樣本。
這樣的事情。
textBox.EditingDidBegin += delegate {
var offset = scrollView.contentOffset;
offset.Y -= 200;
scrollView.contentOffset = offset;
}