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

时间:2015-03-23 16:04:40

标签: ios objective-c

我正在从图像中创建一个新帧,但是当新帧打开时,它就在屏幕上的其他所有内容之后。

有没有办法把它带到前线?

代码:

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;

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

2 个答案:

答案 0 :(得分:1)

您可以将图像放在前面,如下所示:

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

答案 1 :(得分:0)

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

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