重新排列屏幕上的项目,将一个框架放在前面



我正在从图像中制作一个新的框架,但当新框架打开时,它会落后于屏幕上的其他内容。

有办法把它带到前面吗?

代码:

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;
}

我已尝试添加此

[_imageOne.superview bringSubviewToFront:_imageOne];

之后

_imageOne.frame = newFrame;

但这会使图像由于某种原因而消失。。感谢

你可以像这样把你的图像放在前面:

-(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];
   }

我不确定您到底需要什么,但为了将子视图放在前面(在自定义UIView类中):

UIImageView * imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yourimage.png"]];
[self.superview bringSubviewToFront:imgView];

最新更新