簡體   English   中英

如何將特定的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的上方:)

可能幫助我的朋友:

使用此代碼[_imgfull bringSubviewToFront:longg.view]; -(void)longpress:(UILongPressGestureRecognizer *)longg方法

-(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放在最前面:)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM