IOS:创建全屏“叠加”UIView(Monotouch)

时间:2012-12-20 07:48:16

标签: ios xamarin.ios

我在导航控制器中有一个视图,并且想要创建一个“完整(应用程序)屏幕”覆盖图,其中说明了用户应该做什么的一些事情。我已经看到这一点在其他应用程序上有点透明,并且效果很好。我正在尝试下面的内容,但内容最终会在我的navcontroller标题下面。调查讨论了将矩形转换为“窗口级”位置等,但它仍在下面。

以下我的微弱尝试的替代方案?或者样本链接也很棒。

谢谢!

HelpOverlayUIView _overlayView;

    public void PresentHelpOverlay()
    {
        RectangleF windowFullFrame = new RectangleF(0,0,UIScreen.MainScreen.Bounds.Width,UIScreen.MainScreen.Bounds.Height);

        // Conversion?
        //[aView convertPoint:localPosition toView:nil];
        RectangleF overlayFrame = View.ConvertRectFromView(windowFullFrame ,null);

        // Clear old one if it exists.
        if (_overlayView != null) _overlayView = null;

        // Instantiate popup view and add to (in this case the 2nd tier view).  This is in an abstract class, if in a concrete one it'd normally just be View.Add
        _overlayView = new HelpOverlayUIView(this, overlayFrame);

        // tried th, didn't change it.
        // this.WantsFullScreenLayout = true;
        // _childView.BringSubviewToFront(_overlayView);
        _overlayView.Alpha = 0;

        _childView.Add (_overlayView);

        // Setup event to close without doing anything.
        _overlayView.CloseView += (sender, e) => {

            Console.WriteLine ("close called");
            // animate modal popup's departure
            UIView.Animate (
                0.5f,
                () => {
                // Anim Code
                _overlayView.Alpha = 0;
            },
            null
            );

        };

        // animate modal popup's arrival
        UIView.Animate (
            0.5f,
            () => {
            // Anim Code
            _overlayView.Alpha = 1;
        },
        null
        );

    }

(视图只是一个带有Draw()方法重载的UIView,它将文本等放入视图中)

1 个答案:

答案 0 :(得分:1)

您可以将_overlayView添加到视图层次结构中更高的位置,例如NavigationViewController。如果你的NavigationViewController被设置为你的RootViewController(好吧,不管是什么),你可以尝试这个。

((AppDelegate)UIApplication.SharedApplication.Delegate).Window.RootViewController.Add(_overlayView);

你也可以像这样把前面的子视图带到前面,但这只是在那个视图的前面,而不是前面的一切(除非_childView是你的NavigationViewController,否则这不是你想要的)。

_childView.BringSubviewToFront(_overlayView);