将xamarin.forms.view转换为uiview ...?

时间:2016-08-17 10:33:50

标签: view uiview xamarin.ios converter

我在xamarin.iOS项目上工作,我需要将Xamarin.Forms.View转换为UIView。我设法在Android上做我想要的,但不是在iOS上。 我试图使用找到here的这种方法:

public static UIView ConvertFormsToNative(Xamarin.Forms.View view, CGRect size)
{
    var renderer = RendererFactory.GetRenderer (view); 
    renderer.NativeView.Frame = size; 
    renderer.NativeView.AutoresizingMask = UIViewAutoresizing.All;
    renderer.NativeView.ContentMode = UIViewContentMode.ScaleToFill; 
    renderer.Element.Layout (size.ToRectangle()); 
    var nativeView = renderer.NativeView; 
    nativeView.SetNeedsLayout ();
    return nativeView;
}

但它在我的项目中不起作用......

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

不要忘记在appdelegate中使用Xamarin.Forms.Forms.Init();

我尝试使用Xamarin地图控件,但它不起作用。我用这个而且瞧!

public partial class ViewControllerCliente : UIViewController........


var map = new Map(

MapSpan.FromCenterAndRadius(

new Position(37, -122), Distance.FromMiles(0.3)))
{

  IsShowingUser = true,

  HeightRequest = 200,

  WidthRequest = 200,

VerticalOptions = LayoutOptions.FillAndExpand

};


var stack = new StackLayout { Spacing = 0 };

stack.Children.Add(map);


this.Add(ConvertFormsToNative(stack,new CGRect(0, 180, 

UIScreen.MainScreen.Bounds.Width,360)));