Reputation: 15
I'm making a new frame from an image, but when the new frame opens it is behind everything else on the screen.
Is there a way to bring it to the front?
Code:
if ([touch view] == _imageOne)
{
CGRect newFrame = _imageOne.frame;
newFrame.size.width -= 280;
newFrame.size.height -= 280;
newFrame.origin.x += 3.2;
newFrame.origin.y -= 100;
_imageOne.frame = newFrame;
}
else if ([touch view] == _imageTwo)
{
CGRect newFrame = _imageTwo.frame;
newFrame.size.width -= 280;
newFrame.size.height -= 280;
newFrame.origin.x += 95;
newFrame.origin.y -= 100;
_imageTwo.frame = newFrame;
}
I have tried adding this
[_imageOne.superview bringSubviewToFront:_imageOne];
after
_imageOne.frame = newFrame;
but that makes the image just disappear for some reason.. Thanks
Upvotes: 0
Views: 48
Reputation: 418
You can bring your image to the front like this:
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch view] == _imageOne)
{
CGRect newFrame = _imageOne.frame;
newFrame.size.width += 280;
newFrame.size.height += 280;
newFrame.origin.x -= 3.2;
newFrame.origin.y += 100;
_imageOne.frame = newFrame;
[_imageOne.superview bringSubviewToFront:_imageOne];
}
Upvotes: 1
Reputation: 16793
I am not sure what exactly you need, but in order to bring the subview to front (inside the custom UIView class):
UIImageView * imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yourimage.png"]];
[self.superview bringSubviewToFront:imgView];
Upvotes: 0