Domanda

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?

È stato utile?

Soluzione

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

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

Altri suggerimenti

@gesture = UIPinchGestureRecognizer.alloc.initWithTarget(self.faceView,action:'pinch:')

self.faceView.addGestureRecognizer(@gesture)

def pinch(foo)

end

If you don't want the method handler to take an argument, use action:'pinch' instead. It will then look for a method like this:

def pinch

end

Using an instance var (@gesture = ...) is a good idea here because sometimes gesture recognizers and the GC don't play well together if you don't make the gesture var an instance var of a UIViewController. (In my experience)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top