Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用点和多个图像视图_Ios_Uiimageview_Uiimage_Uiinterfaceorientation_Cgpoint - Fatal编程技术网

Ios 使用点和多个图像视图

Ios 使用点和多个图像视图,ios,uiimageview,uiimage,uiinterfaceorientation,cgpoint,Ios,Uiimageview,Uiimage,Uiinterfaceorientation,Cgpoint,我正在使用一个视图控制器,该控制器包含两个UIImageViews。底部图像视图包含一张照片(由用户拍摄或选择)。第二个图像视图位于该视图的顶部,也占据了整个屏幕 第二个图像视图包含一个指针(下例中为绿点)。它用作可在屏幕上定位的可移动视图。它的用途是在它后面的照片上标记一个位置/点 在“纵向”中,此操作正常,底部图像视图设置为“图像=纵横比填充”。因此,拍摄的照片占据了整个屏幕 在横向定位中,这不起作用。我可以用一句话更好地解释 下面的图片画得很糟糕 例如,如果用户选择纵向视图上的点(由绿点

我正在使用一个视图控制器,该控制器包含两个
UIImageView
s。底部图像视图包含一张照片(由用户拍摄或选择)。第二个图像视图位于该视图的顶部,也占据了整个屏幕

第二个图像视图包含一个指针(下例中为绿点)。它用作可在屏幕上定位的可移动视图。它的用途是在它后面的照片上标记一个位置/点

在“纵向”中,此操作正常,底部图像视图设置为“图像=纵横比填充”。因此,拍摄的照片占据了整个屏幕

在横向定位中,这不起作用。我可以用一句话更好地解释

下面的图片画得很糟糕

例如,如果用户选择纵向视图上的点(由绿点显示),则近似位置为220380

然而,如果相同的位置在横向上,它将不在后面照片上的相同位置

这一点可以转化为280300

所以问题是。。。当VC是横向定向时,如何确定图像的高度和宽度(从底部图像视图中)以计算出相同的点

或者是否有其他方法/途径来实现这一点

-------编辑---------- 我已经在中创建了一个测试应用程序,其中仅包含此功能。我的设置与上面详述的相同。我已将日志添加到视图中,并将方向更改为横向。以下是我正在使用的日志:

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

如何从这些结果中确定中心点相对于底部图像坐标的位置?

实际上,您必须在两个方向上将该点转换为图像坐标系。在您给出的示例中,它仅适用于纵向,因为图像与屏幕具有相同的纵横比。如果您有一个正方形图像,则该点与图像没有1:1的关系,并且可以轻松地放置在图像之外

我可以想出两种方法来实现你的目标:

1) 不要让底部的imageview占据整个屏幕并进行纵横比填充,而是根据图像手动调整其大小以占据整个屏幕的宽度或高度。也就是说,如果您有一个1000x1000的图像,您希望portait(iphone3)的图像视图为320x320,或横向视图为300x300。然后,使第二个图像成为第一个图像的子视图。它的位置现在将相对于底部图像的坐标系

2) 使用一些简单的数学将屏幕上的点转换为图像的坐标系。您知道底部图像视图的大小和纵横比,您也知道图像的大小和纵横比

假设图像是640x920。在横向视图中,底部图像视图将为480x300

1) 按图像视图中的大小缩放图像(209x300)

2) 由于图像将居中,它将从左侧约136个点开始

3) 因此,屏幕上的点(280300)将相对于较小的图像转换为(144280[-20点,用于状态栏]),在完整图像的坐标系中转换为(441859)

我希望这为你指明了正确的方向

编辑:

好的,使用示例日志:

[顺便说一句,您可以像这样更容易地打印CGRECT:NSLog(@“%@”、NSStringFromCGRect(self.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) 计算图像视图中图像的帧

x = (photoImageView.frame.size.width - width) / 2;
y = 0;
frame = CGRectMake(x, y, width, height);
3) 假设您使用[touch locationInView:photoImageView]获取位置点,您可以使用

CGRectContainsPoint(frame, location)
编辑-包括实际使用的代码-与上面处理图像视图方向略有不同

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;
if(self.photoImageView.frame.size.height
谢谢,我认为第二种方案是最好的实施方案。然而,这两种方法都能奏效。我选择第二个的原因是因为顶部图像视图使用了过大的图像。这是为了说明imageview的移动,并确保在完全移动到一侧时,视图始终处于屏幕中。然而,我不确定你是如何在你的答案中计算出这些示例点的,请你再详细说明一下好吗?我不确定如何从顶部图像视图的中心点到底部图像的图像坐标以及使用的方法。顶部图像的中心点是相对于整个屏幕还是相对于其自身的superview?它将是相对于屏幕上uiimageview的中心点我已添加了一个编辑问题,在测试中显示我的日志信息