UIImageView를 가운데에 놓고 확대/축소를 수행하려고합니다. 아래 코드에 따라 확대/축소는 정상적으로 작동합니다. 하지만 내 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을 사용하면 scrollview의 델리게이트 (scrollViewDidZoom :')를 통해 동적으로 조절할 수 있습니다. 또 다른 메모로, 'CIImage'를 텍스처로 렌더링하기 위해 MTKView를 사용하면 속도가 매우 빠르며 CIFilter와 뷰를 GPU에 직접 연결할 수 있습니다. 스크롤링/zomming은 실크처럼 부드럽습니다. 화면에 표시되는 CIImage 범위 만 렌더링합니다. 즉, 원래 이미지의 픽셀 화는 없습니다. – SushiHangover