I have a lot of UIImageViews in my main view, some of these have images, others are blank. I have setup code that will check which UIImageView currently contains an image. At the same time, this code will take care of allowing a UIImageView with an image to be moved around.
Now what happens is this: when moving a selected UIImageView around (for some reason and quite randomly), the image will not stay on top of the other UImageViews in the screen. The reason why I say that this is random is because it will stay on top of some of the other views, but not on top of others.
The behavior is unexpected, several problems arise:
UIImageView should slip under another.UIImageViews to be moved only if they contain an image. So if the UIImageView goes under another who does not contain an image, I cannot touch and move it again. It looks like it is stuck in place.Please note that I have not been setting subviews at all for this code, thus why this behavior occurs is beyond me.
So what my question boils down to, is there any way that I can tell the code to:
UIImageView with an image, then allow me to move the UIImageView.UIImageView to supersede (be on top of) all other UIImageViews.Code reference:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{UITouch *touch;
UITouch *touch;
CGPoint touchLocation;
for (UIImageView *fruit in fruitArray)
{
// Check that the UIImageView contains an image
if([fruit image] != nil)
{
// Get the touch event.
touch = [touches anyObject];
// Get the location for the touched object within the view.
touchLocation = [touch locationInView:[self view]];
// Bring the UIImageView touch location to the image's center.
if([touch view] == fruit)
{
fruit.center = touchLocation;
}
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
//allow the selected event (in our case a UIImageView) to be dragged
[self touchesBegan:touches withEvent:event];
}
Thank you for your help! Let me know if you need a better explanation
[self.view bringSubviewToFront:imageView];
This was what you were looking for...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With