tôi không tìm thấy một cách để làm điều đó từ bộ điều khiển phương thức riêng của mình vì vậy tôi tạo ra một lớp và một phương pháp khuyến nông:
public class ModalViewController : UIViewController
{
public SizeF OriginalViewSize { get; private set; }
void Initialize()
{
ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
}
public override void ViewDidLoad()
{
OriginalViewSize = View.Bounds.Size;
base.ViewDidLoad();
}
public ModalViewController (IntPtr handle) : base (handle)
{
Initialize();
}
public ModalViewController (string nibName, NSBundle bundle) : base (nibName, bundle)
{
Initialize();
}
public ModalViewController() : base()
{
Initialize();
}
}
public static class ModalViewControllerExtensions
{
public static void PresentModalViewController (this UIViewController parent, ModalViewController target)
{
parent.PresentViewController (target, true, null);
target.View.Superview.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
target.View.Superview.Frame = new RectangleF (PointF.Empty, target.OriginalViewSize);
target.View.Superview.Center = UIScreen.MainScreen.Bounds.Center().Rotate();
}
}
Đây là khoảng cách tôi sử dụng nó:
this.PresentModalViewController (
new PublishModalViewController (Item, HandlePublishAction)
);
Thuận tiện là tôi không cần chỉ định kích thước rõ ràng vì nó sử dụng các giới hạn của khung nhìn gốc từ trình tạo giao diện. Tôi không chắc làm thế nào phản ứng này để autorotate, nó có thể cần một số điều chỉnh. Tôi cũng đang sử dụng hai phương pháp mở rộng tại đây:
public static PointF Rotate (this PointF pt)
{
return new PointF (pt.Y, pt.X);
}
public static PointF Center (this RectangleF rect)
{
return new PointF (
(rect.Right - rect.Left)/2.0f,
(rect.Bottom - rect.Top)/2.0f
);
}
Và đây là nó.
Nguồn
2012-12-27 01:23:07
Quiet brilliant ... –
Điều đó có vẻ không giống bất kỳ mã iOS nào tôi đã xem. Bạn có thể vui lòng hiển thị điều này chi tiết hơn/ví dụ thực tế không? – iOSProgrammingIsFun
@iOSProgrammingIsFun Câu hỏi này có thẻ MonoTouch (hiện được gắn nhãn là [Xamarin.iOS] (http://xamarin.com/ios)). Đó là một nền tảng để viết trong C# đối với các API của Apple. –