2013-07-29 9 views
0

두 개의 UIImageView을 보유하고있는 뷰 컨트롤러에서 작업하고 있습니다. 하단 이미지보기에는 사진 (사용자가 찍거나 선택한 사진)이 있습니다. 두 번째 이미지 뷰는 전체 화면을 차지하면서이 위에 배치됩니다.포인트 및 다중 이미지 뷰로 작업하기

두 번째 이미지보기에는 포인터 (아래 예제에서는 녹색 점)가 있습니다. 화면에 배치 할 수있는 이동 가능한보기로 사용됩니다. 그 뒤에 사진의 위치/지점을 표시하는 것이 좋습니다.

인물 사진에서는이 이미지가 잘 작동하고 하단 이미지보기가 이미지 = 가로 세로 채우기로 설정됩니다. 따라서 촬영 한 사진이 전체 화면을 차지합니다.

가로 방향에서는이 기능이 작동하지 않습니다. 사용자 (녹색 점으로 표시)를 세로상의 점을 선택하면, I는, 예를 들어

enter image description here

이하의

심하게 그린 이미지와 조금 더 설명 할 대략적인 위치는 220,380입니다.

그러나 동일한 위치가 가로 방향 인 경우 사진 뒤에서 동일한 위치가 아닙니다.

포인트는 280,300에 가깝습니다.

VC가 오리엔테이션 프리젠 테이션 일 때, 동일한 포인트를 처리하기 위해 이미지의 높이와 너비를 (하단 이미지 뷰 내에서) 어떻게 결정합니까?

또는이를 수행하는 다른 방법/접근 방법이 있습니까?

------- EDIT ---------- 위의 기능과 동일한 테스트 응용 프로그램을 만들었습니다. 위에서 설명한 것과 동일한 설정이 있습니다. 보기에 로그를 추가하고 방향을 가로로 변경합니다. 여기에 내가 사용하고있는 로그는 다음과 같습니다

NSLog(@"bottom image view width: %f",self.photoImageView.frame.size.width); 
NSLog(@"bottom image view height: %f",self.photoImageView.frame.size.height); 
NSLog(@"bottom image view frame bounds X: %f",self.photoImageView.frame.origin.x); 
NSLog(@"bottom image view frame bounds Y: %f",self.photoImageView.frame.origin.y); 
NSLog(@"bottom image view bounds X: %f",self.photoImageView.bounds.origin.x); 
NSLog(@"bottom image view bounds Y: %f",self.photoImageView.bounds.origin.y); 
NSLog(@"---------BOTTOM IMAGE VIEW IMAGE DETAILS---------"); 
NSLog(@"bottom image view image width: %f",self.photoImageView.image.size.width); 
NSLog(@"bototm image view image height: %f",self.photoImageView.image.size.height); 
NSLog(@"bottom image view image frame bounds X: %f",self.photoImageView.image.accessibilityFrame.origin.x); 
NSLog(@"buttom image view image frame bounds Y: %f",self.photoImageView.image.accessibilityFrame.origin.y); 

이러한 결과는 다음과 같습니다

2013-07-30 14:58:23.013 SelectPhotoViewTest[3414:c07] ---------VIEW DETAILS--------- 
2013-07-30 14:58:23.014 SelectPhotoViewTest[3414:c07] ---------BOTTOM IMAGE VIEW DETAILS--------- 
2013-07-30 14:58:23.015 SelectPhotoViewTest[3414:c07] bottom image view width: 480.000000 
2013-07-30 14:58:23.016 SelectPhotoViewTest[3414:c07] bottom image view height: 268.000000 
2013-07-30 14:58:23.016 SelectPhotoViewTest[3414:c07] bottom image view frame bounds X: 0.000000 
2013-07-30 14:58:23.017 SelectPhotoViewTest[3414:c07] bottom image view frame bounds Y: 0.000000 
2013-07-30 14:58:23.018 SelectPhotoViewTest[3414:c07] bottom image view bounds X: 0.000000 
2013-07-30 14:58:23.018 SelectPhotoViewTest[3414:c07] bottom image view bounds Y: 0.000000 
2013-07-30 14:58:23.019 SelectPhotoViewTest[3414:c07] ---------BOTTOM IMAGE VIEW IMAGE DETAILS--------- 
2013-07-30 14:58:23.019 SelectPhotoViewTest[3414:c07] bottom image view image width: 258.000000 
2013-07-30 14:58:23.019 SelectPhotoViewTest[3414:c07] bototm image view image height: 480.000000 
2013-07-30 14:58:23.020 SelectPhotoViewTest[3414:c07] bottom image view image frame bounds X: 0.000000 
2013-07-30 14:58:23.021 SelectPhotoViewTest[3414:c07] buttom image view image frame bounds Y: 0.000000 

중심점 아래 이미지 좌표와 관련하여 어디 있는지 결정하기 위해 이러한 결과에서 얻을 어떻게해야합니까?

답변

0

두 방향에서 이미지의 좌표계로 점을 실제로 변환해야합니다. 사용자가 지정한 예제에서는 이미지가 화면과 동일한 가로 세로 비율을 가지기 때문에 세로 방향으로 만 작동합니다. 정사각형 이미지가있는 경우, 포인트는 이미지와 1 : 1의 관계가 없으며 쉽게 이미지 외부에 배치 될 수 있습니다. 대신 하단 이미지 뷰가 전체 화면을 차지 필요없이)

1, 그것을 화면 채우기를 가지고 차지하기 위해 수동으로 크기를 조정 :

나는 내 머리 위로 떨어져 당신의 목표를 달성하기 위해 두 가지 방법을 생각할 수 이미지에 따라 화면의 너비 또는 높이 중 하나를 선택합니다. 나는. 1000x1000 이미지가있는 경우 이미지보기는 인물 (iPhone3)의 경우 320x320이거나 가로보기의 경우 300x300이됩니다. 그런 다음 두 번째 이미지를 첫 번째 이미지의 하위보기로 만듭니다. 그 위치는 하단 이미지의 좌표계에 상대적입니다.

2) 간단한 수학을 사용하여 화면상의 점을 이미지의 좌표계로 변환하십시오. 하단 이미지보기의 크기와 종횡비를 알고 있으면 이미지에 대해 동일한 것을 알 수 있습니다.

이미지가 640x920이라고 가정 해 보겠습니다. 가로 방향의 하단 이미지보기는 480x300입니다. 이미지를 중심으로되기 때문에

1) 이미지보기 것 사이즈의 이미지를 스케일 (209x300)

2), 상기 좌측

3)로부터 136 개의 점을 시작할 따라서 화면의 (280, 300) 지점은 전체 이미지의 좌표계에서 (441, 859)로 변환되는 작은 이미지에 비해 (144, 280 [상태 표시 줄의 경우 -2080 포인트]로 변환됩니다.

올바른 방향으로이 메시지가 표시되기를 바랍니다.

편집 :

좋아, 당신의 예제 로그의 작업 :

[BTW, 당신은 더 쉽게 이런 CGRECT을 인쇄 할 수 있습니다 : NSLog ("%의 @", NSStringFromCGRect (자기 @. photoImageView.frame))]

1)가 이미지보기에 적합 할 수 있도록 화상 사이즈 척도

ratio = photoImageView.frame.size.height/photoImageView.image.size.height; 
height = photoImageView.image.size.height * ratio; 
width = photoImageView.image.size.width * ratio; 

2 F를 계산) 사용 가정 이미지보기

x = (photoImageView.frame.size.width - width)/2; 
y = 0; 
frame = CGRectMake(x, y, width, height); 

3) 내부의 화상의 RAME는 [터치 locationInView는 : photoImageView 상기 터치

CGRectContainsPoint(frame, location) 
으로 이미지 프레임 내에 있는지를 위치 포인트를 얻으려면, 확인할 수

EDIT - 실제 코드를 사용합니다. - 이미지 뷰의 방향을 처리하는 것과 약간 다릅니다.

if (self.photoImageView.frame.size.height < self.photoImageView.frame.size.width) { 
    // This is device and image view is landscape 
    if (self.pushedPhoto.size.height < self.pushedPhoto.size.width) { 
     // The pushed photo is portrait 
     self.photoImageViewRatio = self.photoImageView.frame.size.height/self.pushedPhoto.size.height; 
    } else { 
     // The pushed photo is landscape 
     self.photoImageViewRatio = self.photoImageView.frame.size.width/self.pushedPhoto.size.width; 
    } 

} else { 
    // This is device and image view is portrait 
    if (self.pushedPhoto.size.height < self.pushedPhoto.size.width) { 
     // The pushed photo is portrait 
     self.photoImageViewRatio = self.photoImageView.frame.size.width/self.pushedPhoto.size.width; 

    } else { 
     // The pushed photo is landscape 
     self.photoImageViewRatio = self.photoImageView.frame.size.height/self.pushedPhoto.size.height; 
    } 
} 

self.valueHeight = self.pushedPhoto.size.height * self.photoImageViewRatio; 
self.valueWidth = self.pushedPhoto.size.width * self.photoImageViewRatio; 




float x = (self.photoImageView.frame.size.width - self.valueWidth)/2; 
float y = (self.photoImageView.frame.size.height - self.valueHeight) /2; 
+0

감사합니다. 제 2의 옵션이 구현하기에 가장 좋은 방법이라고 생각합니다. 그러나 둘 다 작동합니다. 두 번째 이미지를 선택하는 이유는 이미지의 크기가 너무 커서 오버 이미지가 사용되기 때문입니다. 이것은 이미지 뷰의 움직임을 고려하고 뷰가 항상 한쪽으로 이동했을 때 항상 화면에 표시되도록합니다. 그러나, 나는 당신이 실제로 당신의 답안에서 그러한 예시적인 포인트들을 어떻게 풀어 냈는지 확신 할 수 없다. 더 자세히 설명해 줄 수 있겠는가? 상단 이미지보기의 중심점에서 하단 이미지의 이미지 중심선 및 사용할 방법에 이르는 방법을 확신하지 못합니다. – StuartM

+0

전체 이미지 또는 자체 슈퍼 뷰와 관련하여 최상위 이미지의 중심점입니까? – robinkunde

+0

화면에 uiimageview의 중심점과 관련이 있습니다. – StuartM