Search code examples
objective-csyntaxrubymotion

Using @selector in RubyMotion


How do I translate the following method call from ObjectiveC to RubyMotion syntax:

[self.faceView addGestureRecognizer:[
    [UIPinchGestureRecognizer alloc] initWithTarget:self.faceView
    action:@selector(pinch:)]];

I got this far:

self.faceView.addGestureRecognizer(
  UIPinchGestureRecognizer.alloc.initWithTarget(
  self.faceView, action:???))

I understand the @selector(pinch:) indicates a delegation to the receiver object pinch method, but how would I do this in RubyMotion? Maybe using a block?


Solution

  • You should be able to just use a string to specify the selector:

    self.faceView.addGestureRecognizer(
      UIPinchGestureRecognizer.alloc.initWithTarget(
      self.faceView, action:'pinch'))