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?
You should be able to just use a string to specify the selector:
self.faceView.addGestureRecognizer(
UIPinchGestureRecognizer.alloc.initWithTarget(
self.faceView, action:'pinch'))
@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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With