删除后不显示ImageView

时间:2013-07-15 12:33:12

标签: iphone uiimage uigesturerecognizer

我有imageView。当我点击imageView它显示。 I used UIGestureRecognizer用于平移,旋转,长按。我使用UILongPressGestureRecognizer删除了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];    
}

2 个答案:

答案 0 :(得分:0)

试试这个:

使用UILongPressGestureRecognizer的minimumPressDuration属性。

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

还可以在UILongPressGestureRecognizer Class Reference developer.apple.com上查看minimalPressDuration属性的更多详细信息

答案 1 :(得分: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;
    }
}