简体   繁体   中英

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

I am creating UIImageview on button click .

This is my code :

     _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];

This is my long press gesture method

[![-(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\];

    }
}

在此处输入图片说明

When user long press the UIImageview i want to move the UIImageview to above ,for eg if user long press the red UIImageview it have to come above the green imageview :)

possible help me friends :

Use this code [_imgfull bringSubviewToFront:longg.view]; in your -(void)longpress:(UILongPressGestureRecognizer *)longg method

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

finally i done my job ,

Notes :

I am stored my UIImageview inside NSMutable array ,then using gesture view tag ,get those particular UIImageview to front position :).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM