gpt4 book ai didi

objective-c - 获取数组中对象的 x, y 坐标

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:50:37 27 4
gpt4 key购买 nike

我有一个 UIImageView 对象,我正在尝试获取它的 x 坐标。我用下面的代码做到这一点

endingPoint.x = myObject.center.x;

现在,如果我在尝试循环遍历并获取每个对象的 x 坐标的数组中有相同的 UIImageView,我该怎么做,如下所示?

endingPoint.x = [posArray objectAtIndex:i].center.x;

我知道这是一个新手问题,但我才刚刚开始使用 iOS。

最佳答案

你非常接近。 objectAtIndex: 但是,返回类型为 id 的对象(指向任何内容的通用指针),因此您不能对其调用 .center (属性) .

您必须使用括号符号向它发送一条消息,如下所示:

endingPoint.x = [[posArray objectAtIndex:i] center].x;

首先将值转换为 (UIImageView *):

endingPoint.x = ((UIImageView *)[posArray objectAtIndex:i]).center.x;

关于objective-c - 获取数组中对象的 x, y 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9389117/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com