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

时间:2016-03-16 09:11:05

标签: ios objective-c uiimageview superview uilongpressgesturerecogni

我正在点击按钮创建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\];

    }
}

enter image description here

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

可能帮助我的朋友们:

2 个答案:

答案 0 :(得分:1)

[_imgfull bringSubviewToFront:longg.view];方法

中使用此代码-(void)longpress:(UILongPressGestureRecognizer *)longg

答案 1 :(得分:0)

-(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放到前面位置:)。