我是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