I have been trying to update two UIImageView elements almost simultaneously. Whilst one should have its position changed (image01), the other should have alter its image file (image02).
The problem here is that when I change image02’s image file, image01’s position data is reset to the center (which is the element’s origin).
I am completely here. Do any of you have any ideas on what is causing this?
Here is the code:
- (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;
}
I realised that the problem was in the redrawing of the screen.
So instead of having the element inserted through the interface builder, I inserted it programatically and kept track of its position in a variable =]