我将视图控制器的视图添加到主窗口。我的视图控制器视图是UIScrollView。 视图的边界设置为500x500,视图确实以正确的大小显示。 但是,如果我旋转设备,滚动视图将最大化并占用所有可用的scpace。
我在任何地方都没有自动调整大小的掩码,也没有更改滚动视图的界限。 什么是更改滚动视图的框架/边界?
this.oPdfController = new PdfViewController(NSUrl.FromFilename("./pdffeatures.pdf"), 2);
this.oPdfController.View.Frame = new RectangleF(new PointF(40, 40), new SizeF(500, 500));
this.oPdfController.View.AutoresizingMask = UIViewAutoresizing.None;
window.AddSubview (this.oPdfController.View);
这是控制器的来源:
using System;
using MonoTouch.UIKit;
using MonoTouch.CoreAnimation;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
using System.Drawing;
namespace PdfViewerTest
{
public class PdfViewController : UIViewController
{
public PdfViewController (IntPtr handle) : base( handle )
{
}
public PdfViewController (NSUrl oUrl, int iPage) : base( )
{
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
public override void LoadView ()
{
base.LoadView ();
UIScrollView oScrollView = new UIScrollView (new RectangleF (new PointF (0, 0), new SizeF(1, 1)));
oScrollView.Delegate = new ScrollViewDelegate (this);
oScrollView.MinimumZoomScale = 1.0f;
oScrollView.MaximumZoomScale = 4.0f;
oScrollView.BackgroundColor = UIColor.ScrollViewTexturedBackgroundColor;
this.View = oScrollView;
}
/// <summary>
/// Gets the scroll view.
/// </summary>
private UIScrollView ScrollView
{
get
{
return this.View as UIScrollView;
}
}
/// <summary>
/// Delegate for the scroll view.
/// </summary>
public class ScrollViewDelegate : UIScrollViewDelegate
{
public ScrollViewDelegate (PdfViewController oParentController) : base( )
{
this.oParentController = oParentController;
}
private PdfViewController oParentController;
public override UIView ViewForZoomingInScrollView (UIScrollView scrollView)
{
// Not implemented here.
return null;
}
}
}
}
答案 0 :(得分:0)
我认为这种奇怪的行为是由于oScrollView
成为窗口的直接子视图
我刚刚测试了你的代码并找不到一个解决方案来保持这个视图结构的良好尺寸,但一个简单的解决方法是添加oScrollView
作为PdfViewController.View
的子视图(刚刚测试过(在模拟器上) ,即使旋转,尺寸也保持不变。
这样,您的第一个代码块应该变为:
this.oPdfController = new PdfViewController(NSUrl.FromFilename("pdffeatures.pdf"), 2);
window.AddSubview (this.oPdfController.View);
和您的控制人员:
using System;
using MonoTouch.UIKit;
using MonoTouch.CoreAnimation;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
using System.Drawing;
namespace PdfViewerTest
{
public class PdfViewController : UIViewController
{
UIScrollView oScrollView = null;
public PdfViewController (IntPtr handle) : base( handle )
{
}
public PdfViewController (NSUrl oUrl, int iPage) : base( )
{
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
public override void LoadView ()
{
base.LoadView ();
oScrollView = new UIScrollView (new RectangleF (new PointF (0, 0), new SizeF(1, 1)));
oScrollView.Delegate = new ScrollViewDelegate (this);
oScrollView.MinimumZoomScale = 1.0f;
oScrollView.MaximumZoomScale = 4.0f;
oScrollView.BackgroundColor = UIColor.ScrollViewTexturedBackgroundColor;
oScrollView.Frame = new RectangleF(new PointF(40, 40), new SizeF(500, 500));
oScrollView.AutoresizingMask = UIViewAutoresizing.None;
this.View.AddSubView(oScrollView);
}
/// <summary>
/// Gets the scroll view.
/// </summary>
private UIScrollView ScrollView
{
get
{
return oScrollView;
}
}
/// <summary>
/// Delegate for the scroll view.
/// </summary>
public class ScrollViewDelegate : UIScrollViewDelegate
{
public ScrollViewDelegate (PdfViewController oParentController) : base( )
{
this.oParentController = oParentController;
}
private PdfViewController oParentController;
public override UIView ViewForZoomingInScrollView (UIScrollView scrollView)
{
// Not implemented here.
return null;
}
}
}
}
HTH