我想這段代碼轉換爲C#,代碼是從蘋果公司的documentation轉換從obj獲得C到C#
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, activeField.frame.origin)) {
CGPoint scrollPoint = CGPointMake(0.0, activeField.frame.origin.y-kbSize.height);
[scrollView setContentOffset:scrollPoint animated:YES];
到目前爲止,這是我的嘗試,我被卡在CGRectValue。
NSDictionary info = n.UserInfo;
SizeF kbSize = ((RectangleF)info[UIKeyboard.FrameBeginUserInfoKey]).Size;
UIEdgeInsets contentInsets = new UIEdgeInsets(0.0f, 0.0f, kbSize.Height, 0.0f);
this.uiScrollView.ContentInset = contentInsets;
this.uiScrollView.ScrollIndicatorInsets = contentInsets;
RectangleF aRect = this.View.Frame;
aRect.Size.Height -= kbSize.Height;
if(!aRect.Contains(_currentField.Frame))
{
PointF scrollPoint = new PointF(0.0f, _currentField.Frame.Y - kbSize.Height);
this.uiScrollView.SetContentOffset(scrollPoint, true);
}
我可能沒有使用正確的類型,有人可以幫助我,或一些替代代碼做類似的事情。 感謝
我不確定你的意思是「我卡在CGRectValue」。調試器是否顯示所有先前提到的變量都具有您期望的值?調試器在aRect = self.view.frame之後顯示有關aRect的內容? – 2012-01-29 01:50:43
我無法將該行轉換爲C#代碼。它不會編譯。請參閱我嘗試的C#代碼。 – 2012-01-29 02:47:41
如何獲得'_currentField'?我也在轉換教程* [iOS SDK:從鍵盤下面保存內容](http://code.tutsplus.com/tutorials/ios-sdk-keeping-content-from-underneath-the-keyboard--mobile -6103)* ... – testing 2014-11-27 11:38:25