我正在尝试将这段代码转换为 C#,代码来自 Apple 的 documentation
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);
}
我可能没有使用正确的类型,有人可以帮助我,或者一些替代代码做类似的事情。 谢谢
最佳答案
想通了:
((NSValue)info[UIKeyboard.FrameBeginUserInfoKey]).RectangleFValue.Size
那应该行得通。虽然我不能让它像我想要的那样工作,但那行代码实际上会编译并转换为 Obj C 代码。
关于c# - 从 Obj C 到 C# 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9050183/