【问题标题】:UIImageView not responding to UIPanGestureRecognizer gestureUIImageView 没有响应 UIPanGestureRecognizer 手势
【发布时间】:2012-02-22 07:59:00
【问题描述】:

我有 2 次观看。这个想法是从第二个视图中选择图像并将其放置在第一个视图上。 问题是我尝试添加平移手势,它没有响应或调用该方法。请帮忙。谢谢

我的第一视图中的代码

- (void)newStampImage: (UIImage *)inImage
{
    stampImageView = [[UIImageView alloc]initWithImage:inImage];
    UIPanGestureRecognizer *stampPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveStamp:)];
    [stampPanGesture setMinimumNumberOfTouches:1];
    [stampPanGesture setMaximumNumberOfTouches:1];
    [stampImageView addGestureRecognizer:stampPanGesture];
    stampImageView.center = self.view.center;
    [self.view addSubview:stampImageView];
}

【问题讨论】:

  • 你设置代理了吗?[stampPanGesture setDelegate:self];
  • @URLArenzo 在代码中看到这一行并检查 Target[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveStamp:)];
  • @samfisher 抱歉,正在移动设备上冲浪。

标签: ios xcode uiview uiimageview uiimage


【解决方案1】:

请添加

stampImageView.userInteractionEnabled = YES;

【讨论】:

  • 太棒了!它现在正在工作。我注意到图像挡住了我的按钮。如何将我的按钮放在前面?谢谢。
  • Classic... UIImageView 是唯一默认 userInteractionEnabled = NO ... @RockBaby - 你应该调用 [self.view bringSubviewToFront:self.myButton];
  • 您可以通过[button bringSubviewToFront: stampImageView];将按钮的图层向上移动
【解决方案2】:

请确保您已完成手势识别设置,我的意思是设置手势识别 属性为yes,那么它可能会起作用。

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多