如何将特定的 UIImageview 移动到视图的顶部?

How to move the particular UIImageview to top of the view?

我在单击按钮时创建 UIImageview。

这是我的代码:

     _imgfull.userInteractionEnabled=YES;
        _imgfull.clipsToBounds = YES;
        //this all for image positioned
        imgpositioned=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,500,500)];
        imgpositioned.userInteractionEnabled=YES;
        imgpositioned.tag=tag;
        tag++;
        if(tag==1)
        {
            imgpositioned.backgroundColor =[UIColor redColor];
        }
        else
        {
            imgpositioned.backgroundColor =[UIColor greenColor];
        }
//pinch gesture 
        UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(Pinchforimage:)];
        pinch.delegate=self;
        [imgpositioned addGestureRecognizer:pinch];

        // create and configure the rotation gesture
        UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGestureDetected:)];
        [rotationGestureRecognizer setDelegate:self];
        [imgpositioned addGestureRecognizer:rotationGestureRecognizer];
        // pan gesture
        UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureDetected:)];
        [panGestureRecognizer setDelegate:self];
        [imgpositioned addGestureRecognizer:panGestureRecognizer];
        //long press gesture
        UILongPressGestureRecognizer *longpress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longpress:)];
        [longpress setDelegate:self];
        [imgpositioned addGestureRecognizer:longpress];
         [_imgfull addSubview:imgpositioned];

这是我的长按手势方法

[![-(void)longpress:(UILongPressGestureRecognizer *)longg
{

    NSLog(@"gesture recogniser long press obtained ==%d",\[longg.view tag\]);
    UIGestureRecognizerState state =\[longg state\];
    if(state ==UIGestureRecognizerStateBegan ||state ==UIGestureRecognizerStateChanged)
    {
        \[imgpositioned superview\];

    }
}

当用户长按 UIImageview 时,我想将 UIImageview 移动到上方,例如,如果用户长按红色 UIImageview,它必须位于绿色 Imageview 上方:)

可能帮助我的朋友:

在您的 -(void)longpress:(UILongPressGestureRecognizer *)longg 方法中使用此代码 [_imgfull bringSubviewToFront:longg.view];

-(void)longpress:(UILongPressGestureRecognizer *)longg
{


    UIGestureRecognizerState state =[longg state];
    if(state ==UIGestureRecognizerStateBegan ||state ==UIGestureRecognizerStateChanged)
    {
        int temptag=[longg.view tag];
        UIImageView *views=(UIImageView *)arrimgstore[temptag];
        NSLog(@"got it to super view %@",views);
        [_imgfull bringSubviewToFront:views];
    }
}

我终于完成了我的工作,

备注:

我将我的 UIImageview 存储在 NSMutable 数组中,然后使用手势视图标签,将那些特定的 UIImageview 放到前面的位置:)。