我在ScrollView中有一个UIImageView。该应用程序允许用户在滚动视图中平移/缩放图像,然后应用程序保存滚动视图的ContentOffset和ZoomScale数据。
当我重新加载ViewController时,我执行以下操作:
myImageView.image = UIImage.FromFile("image.jpg");
myScrollView.SetZoomScale(zoomScale, true);
myScrollView.SetContentOffset(contentOffset, true);但是加载的图像在滚动视图中不会出现在相同的位置。
发布于 2015-01-07 23:57:59
为了保存缩放图像的状态,您需要保存缩放比例和偏移。如果您想用这些变量加载相同的图像,您必须在更新GUI的方法中有一个特定的顺序(初始化控件、更改框架等)。
顺序应该是:-初始化你的控件:
UIImageView imageView = new UIImageView (this.view.bounds);
imageView.Image = image;
imageView.ContentMode = UIViewContentMode.ScaleAspectFit;
imageView.ClipToBounds = true;
UIScrollView scrollView = new UIScrollView (this.View.Bounds);
scrollView.ContentSize = new SizeF (imageView.Frame.Width, imageView.Frame.Height);
scrollView.MaximumZoomScale = 4f;
scrollView.MinimumZoomScale = 1f;
scrollView.ViewForZoomingInScrollView += (UIScrollView sv) => 
{
    return imageView;
};的右侧视图中
this.View.AddSubview (scrollView);
scrollView.AddSubview (imageView);scrollView.SetContentOffset (new PointF (50, 50), false);scrollView.ZoomToRect (new RectangleF (50, 50, 100, 100), false);希望这能有所帮助!祝好运!
https://stackoverflow.com/questions/22277744
复制相似问题