我一直在尝试几乎同时更新两个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;
}
我意识到问题在于重绘屏幕。
因此,我没有通过接口构建器插入元素,而是以编程方式插入它并在变量中跟踪其位置=]