我有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];
}
答案 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;
}
}