2013-07-15 62 views
0

我有imageView。当我点击imageView它显示。用于平移,旋转,longpress的I used UIGestureRecognizer。我用UILongPressGestureRecognizer删除imageview。点击图片后,imageView不显示。删除后ImageView不显示

代码:

-(void)img:(id)sender { 
    [self.view addSubView:myImageView]; 
    UILongPressGestureRecognizer *sslongpress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(sslongPress:)]; 
    [myImageView addGestureRecognizer:sslongpress]; 
} 

-(void)sslongPress:(UILongPressGestureRecognizer*)sender { 
    [myImageView removeFromSuperview];  
} 
+0

我用来调用img方法的按钮 – user2474320

+0

检查'myImageView = nil'吗?你如何创建'myImageView'?你使用ARC还是手动内存管理? – Amar

+0

即时通讯使用ARC ... – user2474320

回答

0

removeFromSuperview属性中删除视图视图不动,用下面的代码来移动使用UILongPressGestureRecognizer您的看法

-(void)sslongPress:(UILongPressGestureRecognizer*)sender { 

    CGPoint point = [sender locationInView:view_.superview]; 

    if (sender.state == UIGestureRecognizerStateBegan) 
    { 
     // myImageView.hidden=NO; 
     myImageView.center=point; 
    } 
    else if (sender.state == UIGestureRecognizerStateChanged) 
    { 
     myImageView.center=point; 
    } 
    else if (sender.state == UIGestureRecognizerStateEnded) 
    { 
     //myImageView.hidden=YES; 
     myImageView.center=point; 
    } 
} 
+0

如何设置myImageView?首先我点击,我需要删除。我点击后,我需要添加myImageView来查看。 – user2474320

+0

你在视图中添加图像视图在超级视图中使用隐藏属性显示uiimageview – NANNAV

+0

它不工作。 – user2474320

0

试试这个:UILongPressGestureRecognizer的

使用minimumPressDuration财产。

sslongpress.minimumPressDuration = _____ ; //_____ = your value 

,也看到minimumPressDuration财产更详细的UILongPressGestureRecognizer Class Reference developer.apple.com超视图

+0

minimumPressDuration仅在ios中可选,默认值为0.5。以秒为单位的时间必须按住手指才能识别手势 – NANNAV