简体   繁体   English

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

[英]Using UIBezierPath do draw in Rubymotion

I am trying to setup a view allow you to draw a signature. 我正在尝试设置一个允许您绘制签名的视图。 All my selectors and UIGestureRecognizors seem to be working based on what i'm getting in my logs but nothing is showing on my screen after movement. 我所有的选择器和UIGestureRecognizors似乎都在根据我在日志中得到的内容进行工作,但移动后屏幕上没有任何显示。 Does anyone see something i'm missing that is not allowing the stroke to show up with my gesture? 有人看到我想念的东西是不允许我的手势出现的吗? Any help would be very appreaciated 任何帮助将不胜感激

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

The RubyMotion samples repo on github, has the code to do what you want to do. github上的RubyMotion示例存储库,具有执行您要执行的操作的代码。 It uses a custom UIView, called PaintView, which has all of the event listeners and methods for drawing code on touches. 它使用一个名为PaintView的自定义UIView,它具有所有事件侦听器和用于在触摸时绘制代码的方法。

Check it out here: 在这里查看:

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

The issue came from using UIViewController vs. UIView. 问题来自使用UIViewController与UIView。 The UIBezierPath only runs under the UIView call. UIBezierPath仅在UIView调用下运行。 After using this my code worked perfect. 使用此代码后,我的代码运行完美。 Thanks. 谢谢。

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

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