我需要使用Xamarin.iOS爲iOS 6 +實現自定義彈出窗口。Xamarin.iOS - 自定義UIPopoverBackgroundView
到目前爲止,除了關閉默認陰影以外,一切正常。這裏是我的實現:
public class PopoverBackgroundView : UIPopoverBackgroundView
{
private UIImageView _arrow, _background;
public override float ArrowOffset { get; set; }
public override UIPopoverArrowDirection ArrowDirection { get; set; }
[Export ("arrowHeight")]
static new float GetArrowHeight()
{
return 39;
}
[Export ("arrowBase")]
static new float GetArrowBase()
{
return 80;
}
[Export ("contentViewInsets")]
static new UIEdgeInsets GetContentViewInsets()
{
return new UIEdgeInsets (25, 25, 25, 25);
}
[Export("wantsDefaultContentAppearance")]
static new bool WantsDefaultContentAppearance
{
get { return false; }
}
public PopoverBackgroundView(IntPtr handle) : base (handle)
{
_background = new UIImageView { Image = Theme.PopoverBackgroundImage };
_arrow = new UIImageView { Image = Theme.PopoverArrowImage };
AddSubview(_background);
AddSubview(_arrow);
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
var arrowFrame = new RectangleF(Frame.Width - GetArrowBase(), -14, GetArrowBase(), GetArrowHeight());
_arrow.Frame = arrowFrame;
var backgroundFrame = Frame;
backgroundFrame.X =
backgroundFrame.Y = 0;
_background.Frame = backgroundFrame;
}
}
這個類很奇怪,因爲你必須「覆蓋」靜態的Objective-C值。在C#中執行此操作的唯一方法是聲明static new
成員並添加Export
屬性。
除了WantsDefaultContentAppearance
之外的所有東西都在工作,它永遠不會被調用。根據Apple文檔here,它將禁用彈出窗口上的默認陰影。有沒有人得到這個與Xamarin.iOS合作?我認爲它可能是一個Xamarin的bug,因爲所有的方法都可以正常工作,而這個恰好是一個屬性。這個類中的方法似乎被定義爲這個類中的「有意使用」的方法,因爲它們看起來比屬性更漂亮。
Apple的'wantsDefaultContentAppearance'是**不是**屬性 - 但是(靜態)方法(就像'arrowHeight'和'arrowBase',而'arrowDirection'和'arrowOffset'是(實例)屬性。 – poupou
Right,so C#中的基類「UIPopoverBackgroundView」將'WantsDefaultContentAppearance'定義爲一個靜態屬性,這是否會中斷導出?我嘗試製作一個靜態方法,就像其他人一樣,它也不會被調用 – jonathanpeppers
It * should *對於吸氣人員來說,因爲簽名是相同的(setter是另外一回事),所以我記得在我的一個應用程序中重寫*箭頭的東西(但對你有用),我看不到任何錯誤在上面 - 所以你最好提交一個錯誤報告並附上一個測試用例,這樣我們可以看看是否有東西丟失。 – poupou