Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.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 目标C:setValue:value forKey:xposition_Ios_Objective C_Setvalue - Fatal编程技术网

Ios 目标C:setValue:value forKey:xposition

Ios 目标C:setValue:value forKey:xposition,ios,objective-c,setvalue,Ios,Objective C,Setvalue,我正在尝试为NSMutableArray中的某些对象创建“动画”效果。我已将其设置为每隔2秒,对象会更改其x值(我不想制作实际动画,因此请不要建议制作动画!): -(无效)左跳{ [自执行选择器:@选择器(jumpRight),对象:零延时:2.0]; 用于(int i=0;i

我正在尝试为NSMutableArray中的某些对象创建“动画”效果。我已将其设置为每隔2秒,对象会更改其x值(我不想制作实际动画,因此请不要建议制作动画!):

-(无效)左跳{
[自执行选择器:@选择器(jumpRight),对象:零延时:2.0];
用于(int i=0;i<[self.jumpArray count];i++){
[self.jumpArray[i]设置值:@(30*i)forKey:“XPOSITION”];
}
}
-(无效)右跳{
[自执行选择器:@选择器(jumpLeft),对象:零延时:2.0];
用于(int i=0;i<[self.jumpArray count];i++){
[self.jumpArray[i]设置值:@(20*i)forKey:“XPOSITION”];
}
}
假设它在整个游戏中持续。我的问题是,我应该输入什么来更改x位置?我试着看看人们都说了些什么,但我什么也没发现。我还尝试了self.jumpArray[I].center=。。。但上面写着“在'id'类型的对象上找不到属性”。有什么建议吗


任何帮助!提前谢谢!

假设
self.jumpArray
UIView
对象的数组,您可以使用setter方法而不是使用属性语法设置中心:

[self.jumpArray[i] setCenter:somePointValue];
另一个选项是使代码更具可读性:

UIView *view = self.jumpArray[i];
view.center = somePointValue;
您还可以使用快速枚举:

for (UIView *view in self.jumpArray) {
    view.center = somePointValue;
}

p、 我知道输入的值不会使其成为“向左跳转”或“向右跳转”“它们或多或少是示例中的占位符。
jumpArray
中的对象是什么?”?它们是某种类型的
UIView
s吗?它们是UILabel--很抱歉没有说明您不能对
id
类型的对象使用属性访问。相反,调用setter方法<代码>[self.jumpArray[i]设置中心:someValue]。谢谢你,rmaddy工作得很好!你愿意把它写下来作为答案,这样我就可以把它标对了吗?
for (UIView *view in self.jumpArray) {
    view.center = somePointValue;
}