簡體   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