繁体   English   中英

使用UIBezierPath确实可以在Rubymotion中进行绘制

[英]Using UIBezierPath do draw in Rubymotion

我正在尝试设置一个允许您绘制签名的视图。 我所有的选择器和UIGestureRecognizors似乎都在根据我在日志中得到的内容进行工作,但移动后屏幕上没有任何显示。 有人看到我想念的东西是不允许我的手势出现的吗? 任何帮助将不胜感激

class SignatureController < UIViewController

 def viewDidLoad

  self.title = "Please Sign"
  self.view.backgroundColor = UIColor.whiteColor
  @path = UIBezierPath.bezierPath
  @path.setLineWidth(2.0)

  pan = UIPanGestureRecognizer.alloc.initWithTarget(self, action: 'pan:')
  pan.maximumNumberOfTouches = pan.minimumNumberOfTouches = 1
  self.view.addGestureRecognizer(pan)
  super

 end

 def pan(pan)
  currentPoint = pan.translationInView(self.view)

  case pan.state

  when UIGestureRecognizerStateBegan
    @path.moveToPoint(currentPoint)
  when UIGestureRecognizerStateChanged
    @path.addLineToPoint(currentPoint)
    NSLog("#{currentPoint}")
  else
    p "SwipeGesture unrecognized"
  end

  self.view.setNeedsDisplay
 end

 def drawRect(rect)
  UIColor.blackColor.setStroke
  @path.stroke 
 end

end

github上的RubyMotion示例存储库,具有执行您要执行的操作的代码。 它使用一个名为PaintView的自定义UIView,它具有所有事件侦听器和用于在触摸时绘制代码的方法。

在这里查看:

https://github.com/HipByte/RubyMotionSamples/tree/master/ios/Paint

问题来自使用UIViewController与UIView。 UIBezierPath仅在UIView调用下运行。 使用此代码后,我的代码运行完美。 谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM