gpt4 book ai didi

ios - 更新图像位置

转载 作者:行者123 更新时间:2023-11-29 03:27:55 25 4
gpt4 key购买 nike

我是 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]];
}
}

最佳答案

您实际上需要为 View 设置新框架。您刚刚更改了 View 原始框架的副本,它与 View 不再有任何联系。

关于ios - 更新图像位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20214712/

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