私はUIImageViewを中央に置き、Zoom on Thatを実行します。以下のコードに従って、ズームインはうまく動作します。しかし私のUIImageViewはNavigationBarの下から始まります。しかし、私はUIImageViewセンターにしたいと同時にセンターを拡大し、中心にUIScrollViewのcontentSizeを拡大します。Xamarin.iOSのUIScrollViewにズームイメージセンターを配置します。
コード:上記のコードのズームから
scrollView = new UIScrollView();
scrollView.Frame = new CGRect(0, 0, View.Frame.Width, View.Frame.Height - 20.0f);
View.AddSubview(scrollView);
dicom_image = new UIImageView(new CGRect(0, 0, View.Frame.Size.Width,300));
dicom_image.Image = dicomItem.uiimage;
dicom_image.UserInteractionEnabled = true;
if (dicomItem.uiimage != null)
{
dicom_image.Image = ExtensionMethods.MaxResizeImage(dicomItem.uiimage, (float)UIScreen.MainScreen.Bounds.Width, (float)UIScreen.MainScreen.Bounds.Width);
dicom_image.ClipsToBounds = true;
dicom_image.TranslatesAutoresizingMaskIntoConstraints = false;
dicom_image.SizeToFit();
};
dicom_image.Center = scrollView.Center;
scrollView.ContentSize = scrollView.Frame.Size;
scrollView.AddSubview(dicom_image);
scrollView.MaximumZoomScale = 3f;
scrollView.MinimumZoomScale = 1f;
scrollView.ViewForZoomingInScrollView += (UIScrollView sv) => { return dicom_image; };
が正常に動作しているが、私は、中心であることをUIImageViewにしたいです。
編集:
このコードは、中心ではなく最初から拡大のための作業罰金が、画像のスタートです。
scrollView = new UIScrollView();
scrollView.Frame = new CGRect(0, 0, View.Frame.Width, View.Frame.Height - 20.0f);
View.AddSubview(scrollView);
dicom_image = new UIImageView(new CGRect(0, 0, View.Frame.Size.Width,300));
dicom_image.Image = dicomItem.uiimage;
dicom_image.ContentMode = UIViewContentMode.Center;
dicom_image.UserInteractionEnabled = true;
if (dicomItem.uiimage != null)
{
dicom_image.Image = ExtensionMethods.MaxResizeImage(dicomItem.uiimage, (float)UIScreen.MainScreen.Bounds.Width, (float)UIScreen.MainScreen.Bounds.Width);
dicom_image.ClipsToBounds = true;
dicom_image.TranslatesAutoresizingMaskIntoConstraints = false;
dicom_image.SizeToFit();
};
dicom_image.Center = scrollView.Center;
scrollView.ContentSize = dicom_image.Frame.Size;
scrollView.AddSubview(dicom_image);
scrollView.ShowsVerticalScrollIndicator = false;
scrollView.ShowsHorizontalScrollIndicator = false;
scrollView.MaximumZoomScale = 3f;
scrollView.MinimumZoomScale = 1f;
scrollView.ViewForZoomingInScrollView += (UIScrollView sv) => { return dicom_image; };
UITapGestureRecognizer doubletap = new UITapGestureRecognizer(OnDoubleTap)
{
NumberOfTapsRequired = 2 // double tap
};
scrollView.AddGestureRecognizer(doubletap);
助けてください。
私はセンターを設定する方法ユーザが指でズームする場合の制約を使用した画像。 – Ironman
@Ironmanでは、スクロールビューのデリゲート( 'scrollViewDidZoom:')を使ってそれらを動的に調整します。別の注意として、 'MTKView'を使って' CIImage'をテクスチャとしてレンダリングするのは速く、CIFilterとビューを直接GPUに連結することができます。スクロール/ズームはできるだけ滑らかです画面に表示されているCIImageエクステントをレンダリングします。つまり、元の画像のピクセル化はしません;-) – SushiHangover