Code Monkey home page Code Monkey logo

swiftydraw's People

Contributors

awalz avatar blu3mo avatar coledunsby avatar dcooley avatar ddaddy avatar dylanshine avatar klinkert0728 avatar linusgeffarth avatar mikhailzimin avatar msztech avatar rivera-ernesto avatar talaviram avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftydraw's Issues

Interested in the sample rate

Hi,

Love this framework! Quick question, is there a way to know the sample rate of touches it picks up or adjust that rate? Thanks!!

Karunya

How to add fill and stroke in draw mode?

Just like in shapes like eclipse, we can fill the shape and add stroke to that shape with any color, how can we achieve this while being in draw mode?

I just want that whatever I draw, it should have a stroke and a fill of different colours. Kind of like a boundary around whatever I draw.

something like this
problems_with_vcc_report_1

Apple Pencil Support

I'm considering adding a property that, if set, will only draw if the screen is touched with Apple Pencil. (It would be as easy as checking the source of the touch)

Also, we could detect the event from Apple Pencil (double tap) to switch the tools currently being used.

What do you think of the idea? I can work on this.

Support for drawing dots

Hello, Linus! Thank you for improving the best drawing framework for iOS! Is it possible to add the single dots drawing support? Currently if you do single taps in the sample project, nothing happens. Anton

Selection brush

A selection brush (that already exists but doesn't work yet) would be nice to have.
You would draw a circle around a few lines, the selection would make a copy of those lines, add a draggable view to the view controller, and drop the lines somewhere the users chooses to:

selection_demo

Swift 5

The Readme ays this is Swift 5 compatible, but it does not compile with Swift 5 through Carthage. The build asks to convert to Swift 5, so it looks like a new Swift 5 release is needed.

Value of type 'SwiftyDrawView' has no member of the following

Value of type 'SwiftyDrawView' has no member 'getCurrentPathArray'
and
Value of type 'SwiftyDrawView' has no member 'setCurrentPathArray'

from this line of code
if self.signature != nil { self.signatureCanvas.setCurrentPathArray((self.signature?.getCurrentPathArray())!) }

SwiftyDraw 2.3
iOS 13.5
Xcode 11.5
Swift 4.2

Update cocoapods

I love SwiftyDraw. Can you please update cocoapods to version 2.0?

continue line

I've updated the touchesBegan function in my forked repo to experiment adding a 'continue path' functionality, where the line you draw will automatically continue from the last one you did (if it exists)

continuousLine

Is something like this worth adding into the library?


The updated touchesBegan() looks like

    /// Determines whether the path should continue from the last touch point.
    public var shouldContinuePath = false


    override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        guard isEnabled, let touch = touches.first else { return }
        if #available(iOS 9.1, *) {
            guard allowedTouchTypes.flatMap({ $0.uiTouchTypes }).contains(touch.type) else { return }
        }
        guard delegate?.swiftyDraw(shouldBeginDrawingIn: self, using: touch) ?? true else { return }
        delegate?.swiftyDraw(didBeginDrawingIn: self, using: touch)
        
        firstPoint = shouldContinuePath && previousPoint != .zero ? previousPoint : touch.location(in: self)
        setTouchPoints(touch, view: self)
          
        let newLine = DrawItem(path: CGMutablePath(),
                           brush: Brush(color: brush.color.uiColor, width: brush.width, opacity: brush.opacity, blendMode: brush.blendMode), isFillPath: false)
        if shouldContinuePath && currentPoint != .zero {
            // draw a straight line between the end of the last touch point
            // and this new touch point
            newLine.path.addPath(createNewStraightPath())
        }
        addLine(newLine)
    }

'addLine' is inaccessible due to 'internal' protection level

The #40 PR added an ability to encode/decode draw data, but appropriate function has "internal" protection level by default. While trying to use it, Xcode says 'addLine' is inaccessible due to 'internal' protection level, so if I install library via CocoaPods or other dependency manager, it's impossible to use addLine() without manual source code editing.

We just need to mark it as "open".

SwiftyDrawView(frame: X.frame)

Hi sir. Im sorry if I disturb you. But this what problem I encountered and I don't know if this relates to your pod.

This view with grey background is my sketch view (a view inside view controller)

screen shot 2018-12-03 at 1 41 35 pm


screen shot 2018-12-03 at 1 44 15 pm

The problem here is that when I draw it overlaps to my sketchview, and i can't draw in the upper portion of the sketchview (please just look at the screenshot)
47394805_2159346874124117_4969836847250276352_n

Support for "soft" brushes

Is there a possibility to get support for soft brushes? (progressive opacity, solid inside, more clear on edges). I tried to do it with a combination of context.setShadow(...) and multiple drawings of the same path, but this is not perfect. I couldn't do it via "stroking" bitmap, tried everything really.

How to zoom in the view & rotate ?

Hi I'm trying to make your view rotate & zoom.
For the zooming part I can implement the gesture in the viewDidLoad :

let gesture = UIPinchGestureRecognizer(target: self, action: #selector(pinchAction(sender:))) self.drawView.addGestureRecognizer(gesture)

and adding this function :
@objc func pinchAction(sender:UIPinchGestureRecognizer) { let scale:CGFloat = previousScale * sender.scale self.view.transform = CGAffineTransform(scaleX: scale, y: scale); previousScale = sender.scale }

  • adding the variable

var previousScale:CGFloat = 1.0

but my strategy isn't working for the rotation (or translation ?) since it's not detecting this as a proper rotation event ?

Do you have any idea how to fix this ?

Thanks for you repo & awesome work by the way !

Delegate methods are never called?

Thanks for this! I dragged SwiftyDraw to my project. I added this to viewDidLoad():

  let drawView = SwiftyDrawView(frame: self.view.frame)
    self.view.addSubview(drawView)

I also made the UIViewController a SwiftyDrawViewDelegate. None of the delegate methods (began, ended) are called.

How to save drawing as an image?

Is there a way to convert the drawing of a SwiftyDraw view to a UIImage? Is there like a property I can access like drawView.image or drawView.saveImage(), or some other method by accessing its contents (I know there a lines property) and converting this into a UIImage? Thanks in advance.

blendMode

I set the drawView background color to orange. I change blend Mode is 'clear' after I draw. The erase part can not have an orange background. How can I fix it?

Line color did not change when button is clicked

Hello! Sorry i dont know if this is an issue, or im just wrong on using it (sorry, im new at ios dev)

@IBAction func markerButtonPressed(_ sender: Any) {
    drawView.brush.color = .red
    drawView.brush = Brush.thick
 }

The problem is that when I clicked the button, it doesn't change the color of the line.

screen shot 2018-11-28 at 4 35 39 pm

FPS Drop

Hello! I faced FPS drop on the draw() method, if a lot of lines will be in the drawing bounds. Any ideas about it?

how to getCropped Image only without the background

Hi ,
I did see this
it worked to get an image with the background space

for example, if the UIView is 200X200
and I did draw in the corner
when I get the image will be 200X200
with all the empty space and with the drawing I did in the corner

I want the get only the draw without the empty spaces

before I use this library I was using
YPDrawSignatureView

and it did it like this

// Save the Signature (cropped of outside white space) as a UIImage
 public func getCroppedSignature(scale:CGFloat = 1) -> UIImage? {
     guard let fullRender = getSignature(scale:scale) else { return nil }
     let bounds = self.scale(path.bounds.insetBy(dx: -strokeWidth/2, dy: -strokeWidth/2), byFactor: scale)
     guard let imageRef = fullRender.cgImage?.cropping(to: bounds) else { return nil }
     return UIImage(cgImage: imageRef)
 }

I did try to do a similar thing with this library but with no luck

Public init of SwiftyDrawView.Line

Hello, guys.
Can you allow initialise Line out of library? It necessary for exit and returning to working on the picture. Just this.
public init(path: CGMutablePath, brush: Brush) { self.path = path self.brush = brush }

Change Line Colour

Andrew, hello!

Just a quick question - I am trying to change colour of a line, however, whenever I press on a button Xcode throws a breakpoint and says - "unexpectedly found nil while unwrapping an Optional value" on a line of drawView.lineColor= button.color

This error is always pretty easy to solve but now I cannot find a solution to it... Here is my piece of code:

class PhotoViewController: UIViewController, SwiftyDrawViewDelegate {

private var backgroundImage: UIImage?

var drawView : SwiftyDrawView!

var cancelButton: UIButton!
var shareButton: UIButton!
var drawButton: UIButton!
var saveButton: UIButton!
var doneButton: UIButton!

var redButton : ColorButton!

init(image: UIImage) {
    self.backgroundImage = image
    super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
    super.viewDidLoad()

    self.view.backgroundColor = UIColor.gray
    let backgroundImageView = UIImageView(frame: view.frame)
    backgroundImageView.contentMode = .scaleAspectFill
    backgroundImageView.image = backgroundImage
    view.addSubview(backgroundImageView)
    addButtons()
}

func addButtons() {
    
    cancelButton = UIButton(frame: CGRect(x: 10.0, y: 10.0, width: 50.0, height: 50.0))
    cancelButton.showsTouchWhenHighlighted = true
    cancelButton.setImage(#imageLiteral(resourceName: "Close"), for: UIControlState())
    cancelButton.addTarget(self, action: #selector(cancel), for: .touchUpInside)
    view.addSubview(cancelButton)
    
    saveButton = UIButton (frame: CGRect(x: 16.0, y: 503.0, width: 50, height: 50))
    saveButton.showsTouchWhenHighlighted = true
    saveButton.setImage(#imageLiteral(resourceName: "Save"), for: UIControlState())
    saveButton.addTarget(self, action: #selector(save), for: .touchUpInside)
    view.addSubview(saveButton)
    
    shareButton = UIButton (frame: CGRect(x: 240.0, y: 484.0, width: 60, height: 60))
    shareButton.showsTouchWhenHighlighted = true
    shareButton.setImage(#imageLiteral(resourceName: "Share"), for: UIControlState())
    shareButton.addTarget(self, action: #selector(share), for: .touchUpInside)
    view.addSubview(shareButton)
    
    drawButton = UIButton (frame: CGRect(x: 260.0, y: 10.0, width: 50, height: 50))
    drawButton.showsTouchWhenHighlighted = true
    drawButton.setImage(#imageLiteral(resourceName: "Draw"), for: UIControlState())
    drawButton.addTarget(self, action: #selector(draw), for: .touchUpInside)
    view.addSubview(drawButton)
    
}

func draw() {
    
    let drawView = SwiftyDrawView(frame: self.view.frame)
    drawView.delegate = self
    self.view.addSubview(drawView)
    
    let cancelButton = UIButton(frame: CGRect(x: 10.0, y: 10.0, width: 50.0, height: 50.0))
    cancelButton.showsTouchWhenHighlighted = true
    cancelButton.setImage(#imageLiteral(resourceName: "Close"), for: UIControlState())
    cancelButton.addTarget(self, action: #selector(cancel), for: .touchUpInside)
    view.addSubview(cancelButton)
    
    let doneButton = UIButton(frame: CGRect(x: 260.0, y: 10.0, width: 50.0, height: 50.0))
    doneButton.showsTouchWhenHighlighted = true
    doneButton.setImage(#imageLiteral(resourceName: "Done"), for: UIControlState())
    doneButton.addTarget(self, action: #selector(cancel), for: .touchUpInside)
    view.addSubview(doneButton)
    
    let redButton = ColorButton(frame: CGRect(x: 10, y: self.view.frame.height - 50, width: 40, height: 40), color: UIColor.red)
    redButton.showsTouchWhenHighlighted = true
    redButton.addTarget(self, action: #selector(colorButtonPressed(button:)), for: .touchUpInside)
    self.view.addSubview(redButton)
    
    UIView.animate(withDuration: 0.1, animations: {
        self.cancelButton.alpha = 0.0
        self.shareButton.alpha = 0.0
        self.saveButton.alpha = 0.0
        self.drawButton.alpha = 0.0
    })
}

func colorButtonPressed(button: ColorButton) {
    drawView.lineColor = button.color
}

func SwiftyDrawDidBeginDrawing(view: SwiftyDrawView) {
}

func SwiftyDrawIsDrawing(view: SwiftyDrawView) {
}

func SwiftyDrawDidFinishDrawing(view: SwiftyDrawView) {
}

func SwiftyDrawDidCancelDrawing(view: SwiftyDrawView) {
}

Also, what would be your advice on merging background image with the drawing?

Thank you, Andrew!

Carthage Installation Support

It'd be great to be able to install SwiftyDraw via Carthage. They have some notes on adding Carthage support to a framework here.

I might have a go at implementing this myself over the next few days, but wanted to open an issue to track any discussion/thoughts.

Xcode 14 Support

When building with Xcode 14 the following build error is encountered for allowedTouchTypes and pencilInteraction.

Stored properties cannot be marked potentially unavailable with '@available'


Since Xcode 14 drops support for iOS 10 and below, just removing @available from allowedTouchTypes should be just fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.