我是iOS新手。我试图在特定位置绘制图像。我使用NSMutableArray来存储它的位置。更新图片职位
// I am calling addCutter method in init method of ViewController
- (void) addCutter
{
//gameModel.cutters is NSMutable Array for position
[gameModel.cutters addObject:[NSValue valueWithCGRect:gameModel.cutterRect]];
cutter = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cutter.png"]];
//cutter is UIImageView
[cutter setFrame:[[gameModel.cutters objectAtIndex:[gameModel.cutters count]-1] CGRectValue]];
cutter.tag = [cutters count] + 100;
[cutters addObject:cutter];
[self.view addSubview:[cutters objectAtIndex:([cutters count]-1)]];
}
,但图像不更新其位置
//code for update the position
-(void) moveCutter
{
for(int i=0;i<[gameModel.cutters count]-1;i++)
{
CGRect newCutterRect = [[gameModel.cuttersobjectAtIndex:i] CGRectValue];
newCutterRect.origin.x += [[disX objectAtIndex:i]floatValue];
newCutterRect.origin.y += [[disY objectAtIndex:i]floatValue];
[gameModel.cutters replaceObjectAtIndex:i withObject:[NSValue valueWithCGRect:newCutterRect]];
}
}
如何为没有,它仍然没有改变 – user2546410