图像不会填充外部屏幕

时间:2012-10-02 20:24:16

标签: ios xamarin.ios

我正在构建一个MonoTouch应用程序,它在iOS设备屏幕上显示UI,并通过HDMI在第二个屏幕上显示图像。在UIImageView中显示图像时,图像不会填满第二个屏幕。以下是在外部屏幕上设置和显示图像的代码。 UIScreen.Screens [1]的宽度和高度给出了正确的值1920/1080。当我显示图像时,我在顶部/底部有一个1英寸的边框,在左/右边有1.5英寸的边框。使用具有类似外部屏幕设置的MPMoviePlayerController填充屏幕。

    public void SetImageExternal(string imageFile)
    {
        if(string.IsNullOrEmpty(imageFile) == false)
        {
            UIScreen externalScreen;
            UIWindow externalWindow;
            UIView externalView;
            UIImageView externalImageView;
            SizeF externalScreenSize;

            if(UIScreen.Screens.Length > 1)
            {

                if(externalWindow != null)
                    externalWindow.Dispose();
                externalWindow = null;

                externalScreenSize = new SizeF();
                externalScreenSize.Width = 0;
                externalScreenSize.Height = 0;
                UIScreenMode maxScreenMode = null;
                externalScreen = UIScreen.Screens[1];

                // Use the screen with the largest width
                for(int i = 0; i < externalScreen.AvailableModes.Length; i++)
                {       
                    UIScreenMode current = UIScreen.Screens[1].AvailableModes[i];
                    if(current.Size.Width > externalScreenSize.Width)
                    {
                        externalScreenSize = current.Size;
                        maxScreenMode = current;
                    }
                }

                externalScreen.CurrentMode = maxScreenMode;

                externalWindow = new UIWindow(new RectangleF(0, 0, externalScreenSize.Width, externalScreenSize.Height));
                externalWindow.RootViewController = new UIViewController(); // create dummy root view controller
                externalWindow.UserInteractionEnabled = false;

                externalImageView = new UIImageView(externalWindow.Frame);          
                externalImageView.Image = UIImage.FromBundle(imageFile);
                externalImageView.ContentMode = UIViewContentMode.ScaleToFill;

                externalView = new UIView(externalWindow.Frame);
                externalView.AddSubview(externalImageView);

                foreach(UIView view in externalWindow.Subviews)
                    view.RemoveFromSuperview();
                externalWindow.AddSubview(externalView);
                externalWindow.MakeKeyAndVisible();
                externalWindow.Hidden = false;
                externalWindow.Screen = externalScreen;
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

我相信ContentMode会判断如何缩放内容的预渲染版本。

但是UIImageView根据UIImage的LeftCapWidth和TopCapHeight的参数确定图像的缩放方式,只有在没有设置的情况下才使用ContentMode。