我要做的是:UIImageView
内有一个UIScrollView
用于缩放目的。现在,当我缩小时,我应该可以在屏幕上的任何位置移动/平移图像。为此,我有一个UIscrollView
(父),其中UIScrollview
(子)与图像。
我使用的代码是:
void SetTestImageSettings()
{
//mainScrollView is Parent scrollview.
mainScrollView = new UIScrollView (
new RectangleF (this.mainImgView.Frame.X, this.mainImgView.Frame.Y, this.mainImgView.Frame.Width +50
, this.mainImgView.Frame.Height +50));
mainScrollView.ContentSize = new SizeF (mainScrollView.Frame.Width + 500, mainScrollView.Frame.Height + 500);
mainScrollView.BackgroundColor = UIColor.Red;
mainScrollView.ContentMode = UIViewContentMode.Center;
//I tried implementing these events, but I am not sure, what to set, I mean I know I should add contentOffset, but what value?
mainScrollView.WillEndDragging += HandleWillEndDragging;
mainScrollView.DraggingEnded += HandleDraggingEnded;
// create our scroll view that has Image
scrollView = new UIScrollView (
new RectangleF (this.mainImgView.Frame.X, this.mainImgView.Frame.Y, this.mainImgView.Frame.Width
, this.mainImgView.Frame.Height - toolBar.Frame.Height));
mainScrollView.AddSubview (scrollView);
View.AddSubview (mainScrollView);
// create our image view
imageView = new UIImageView (mainImage);
scrollView.ContentSize = imageView.Image.Size;
scrollView.ContentMode = UIViewContentMode.Center;
scrollView.ShowsHorizontalScrollIndicator = false;
scrollView.ShowsVerticalScrollIndicator = false;
scrollView.AddSubview (imageView);
// set allow zooming
scrollView.MaximumZoomScale = 3f;
scrollView.MinimumZoomScale = .1f;
scrollView.ViewForZoomingInScrollView += (UIScrollView sv) => { return imageView; };
}
现在每一次,我拖尾,孩子crollview(带图像)在左上角反弹。
任何帮助将不胜感激。此外,任何Objective-C开发人员的帮助也将受到赞赏。我希望我的问题听起来很清醒。
提前致谢。
答案 0 :(得分:0)
我使用的替代方案是:我摆脱了UIScrollview
并在UIImageView
本身添加了手势。平移和捏合手势,我可以放大,也可以在屏幕上平移/移动我的图像。它现在更简单,也在我的控制之下:))