c# - 从 Obj C 到 C# 的转换

标签 c# .net objective-c xamarin.ios uikeyboard

我正在尝试将这段代码转换为 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/

相关文章:

c# - 使用带有 C# 的 API 将配置文件添加到 Google Analytics

c# - Financial.IRR 未在 C# 中计算

c# - 在 WPF 中访问 Window 类中的 Application 对象?

.net - WPF 中的依赖属性和附加属性有什么区别?

c# - '/' 应用程序中的服务器错误

ios - Pocket SDK 有一个执行 API 调用的方法,我将如何使用它?

ios - 我可以为 iPhone 和 iPad 提供两个单独的应用程序吗?

c# - 如何在 Firefox 中打印 RDLC 报告

.net - 如何为多个解决方案配置 TeamCity Inspections (.NET) Runner

ios - 为什么我在尝试将对象添加到 NSMutableArray 时会收到 SIGABRT