0

Я создаю UIImageview при нажатии кнопки.Как переместить конкретный 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 выше, например, если пользователь долго нажимает красную UIIma geview он должен прийти над зеленым ImageView :)

возможно помочь мне друзья:

+0

использовать это - https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/bringSubviewToFront: – Skywalker

ответ

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 arr ay, затем используя тег представления жестов, получите эти особенности UIImageview на переднее положение :).

1

Используйте этот код [_imgfull bringSubviewToFront:longg.view]; в методе -(void)longpress:(UILongPressGestureRecognizer *)longg