Ian*_*ink 19 c# mono xamarin.ios ios cgrect
我正在尝试将Objective-C中的这个居中代码片段转换为MonoTouch
imageView.frame.origin.x = CGRectGetMidX(view.bounds) -
CGRectGetMidX(imageView.bounds)
Run Code Online (Sandbox Code Playgroud)
但找不到哪里Origin.
pou*_*pou 40
MonoTouch映射GCRect到,System.Drawing.RectangleF因为它更接近.NET开发人员一直使用的(例如System.Drawing/Windows Forms ...).
因此imageView.frame.origin.x将变得imageView.Frame.Location.X可以简化imageView.Frame.X.
如果您添加using MonoTouch.CoreGraphics;到源文件,您将获得可为您提供CGRectGetMidX替换的扩展方法,例如
views.Bounds.GetMidX ()
Run Code Online (Sandbox Code Playgroud)
所以
imageView.frame.origin.x = CGRectGetMidX(view.bounds) - CGRectGetMidX(imageView.bounds);
Run Code Online (Sandbox Code Playgroud)
应该成为
imageView.Frame.X = view.Bounds.GetMidX () - imageView.Bounds.GetMidX ();
Run Code Online (Sandbox Code Playgroud)