我一直在尝试几乎同时更新两个 UIImageView 元素。一个应该改变它的位置(image01),另一个应该改变它的图像文件(image02)。
这里的问题是,当我更改 image02 的图像文件时,image01 的位置数据被重置为中心(即元素的原点)。
我完全在这里。你们中有人对造成这种情况的原因有任何想法吗?
这是代码:
- (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch* touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
// Setting crosshair new position
[self setCrossHairPosition:point];
// Getting camera preview, and discovering pixel color at touch location
// I also set colorName here
[self captureNow:touch];
// Getting file and inserting it in the UIImageView
fileName = [NSString stringWithFormat:@"%@.png", colorName];
_colorADDPreview.image = [UIImage imageNamed:fileName];
}
- (void) setCrossHairPosition:(CGPoint)point {
CGRect crossHairRect = _crossHair.frame;
crossHairRect.origin.x = point.x - (crossHairRect.size.width/2);
crossHairRect.origin.y = point.y - (crossHairRect.size.height/2);
_crossHair.frame = crossHairRect;
}