【问题标题】:Objective C: UILongPressGesture on ScrollView目标 C:滚动视图上的 UILongPressGesture
【发布时间】:2012-01-20 07:40:35
【问题描述】:

我正在 UIScrollView 上尝试此代码,但它不起作用。 NSLog 没有出现在我的控制台上。怎么了?它不在 UIScrollView 上时工作正常。

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self papers];

    UIGestureRecognizer *recognizer = [[ UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
    longPressGR = (UILongPressGestureRecognizer *)recognizer;
    longPressGR.minimumPressDuration = 0.5;
    [Image1 addGestureRecognizer:longPressGR];
}

-(void) handleLongPress:(UILongPressGestureRecognizer *)recognizer  { 

    NSLog(@"Long Press");
}

【问题讨论】:

  • 这是像课堂作业还是什么的? 2个人问同样的问题哈哈。 stackoverflow.com/questions/8937458/…
  • 哈哈!是的,也许你看到了我的朋友拉米罗。我们正在尝试先自己解决。

标签: objective-c ios uiscrollview uigesturerecognizer


【解决方案1】:

你没有说 Image1 是什么。我猜是 UIImageView,在这种情况下你需要确保你这样做:

[Image1 setUserInteractionEnabled:YES];

(与大多数视图不同,UIImageView 默认禁用交互。)

(顺便说一句,在 Objective-C 中,让您的 ivars 和方法以小写字母开头是惯例;类以大写字母开头。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-14
    • 1970-01-01
    相关资源
    最近更新 更多