如何将以下方法调用从ObjectiveC转换为RubyMotion语法:
[self.faceView addGestureRecognizer:[
[UIPinchGestureRecognizer alloc] initWithTarget:self.faceView
action:@selector(pinch:)]];
我到目前为止:
self.faceView.addGestureRecognizer(
UIPinchGestureRecognizer.alloc.initWithTarget(
self.faceView, action:???))
我理解@selector(pinch:)
表示接收器对象pinch
方法的委托,但我如何在RubyMotion中执行此操作?也许用块?
您应该只能使用字符串来指定选择器:
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
如果您不希望方法处理程序接受参数,请改用action:'pinch'
。然后它会寻找这样的方法:
def pinch
end
使用实例var(@gesture = ...
)在这里是一个好主意,因为如果你没有使手势var成为UIViewController的实例变量,有时手势识别器和GC不能很好地协同工作。 (在我的经验中)