longitachi/ZLImageEditor

Support custom ZLEditImageViewController

hoangnam714 opened this issue · 21 comments

Hi,
I have an interface like this
Screen Shot 2022-05-13 at 10 58 23
Can I customize something for ZLEditImageViewController, background can't be zoomed and cropped, allows adding images from phone gallery instead of existing emojis

In the next version, I will change the authority of ZLEditImageViewController to open. You can subclass this class to customize something.

I hope you can release a new version soon, for now can I use your code for commercial application, I need to edit the included toolkit

@longitachi Do you can exchange quickly through applications such as slack, message, whatapp,...

Can you accept my invitation to join my workspace, I have some questions

Can you accept my invitation to join my workspace, I have some questions

No, here is my whatsapp id: longitachi

The license is MIT, so you can use this software in commercial applications.

Thank you for your help, I hope to be able to contribute something in the future
ZLImageEditor

oh no, can you support ZLEditImageViewController to UIVIew so I can embed into another viewcotroller, this makes it easier to customize ui of ZLEditImageViewController, currently I can only present ZLEditImageViewController @longitachi

You could instatiate the VC and use it's view property to embed in another VC as child or so...

@shadzik
Screen Shot 2022-05-15 at 21 29 25
Looks like @longitachi forgot to publicize the ZLEditImageViewController constructor, so I can't do it the way you suggested.

Yes, you're right, for the time being you could just make the init method public. Or create a PR that publishes a convenient init method.

@shadzik Screen Shot 2022-05-15 at 21 29 25 Looks like @longitachi forgot to publicize the ZLEditImageViewController constructor, so I can't do it the way you suggested.

1.1.1 fixed

that's right you can create a delegate func addImageStickerView, addTextStickersView so that anyone can create a screen to select their favorite image like this for example
IMG_159C057337B7-1
it would be great if you support this too, thank you so much

You can do it like this

class ImageStickerContainerView: UIView, ZLImageStickerContainerDelegate {

    func show(in view: UIView) {
        let vc = ImageStickerViewController()
        vc.hideBlock = { [weak self] in
            self?.hide()
        }
        getTopViewController()?.showDetailViewController(vc, sender: nil)
    }

}


class ImageStickerViewController: UIViewController {

    var hideBlock: (() -> Void)?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        // Do any additional setup after loading the view.
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        hideBlock?()
    }
    
}

Ohno... @longitachi
I see some of the following problems:

  • bottomShadowView in ZLEditImageViewController.swift:485 is I think it's not needed, it causes error when hiding bottomShadowView
  • how can i scale to fill my image with mainScrollView, i use public parameter version 1.1.1 but it doesn't work, the image i included has black background
    IMG_BAA9112290F7-1

I think it would be better if you fork this repo and then add the custom features you need...

@longitachi Thank you for your help,
Screen Shot 2022-05-18 at 10 19 27

I tried with some code and found the following code works quite well, but I am confused when applying this code to ZLImageStickerView pangeture and ZLTextStickerView, can you help me. Below is the support code

@objc func handlePan(_ gesture: UIPanGestureRecognizer) {
        
        let translation = gesture.translation(in: _Container_image_view)
        guard let gestureView = gesture.view else {
            return
        }
        gestureView.center = CGPoint(
            x: gestureView.center.x + translation.x,
            y: gestureView.center.y + translation.y
        )
        gesture.setTranslation(.zero, in: _Container_image_view)
        
        guard gesture.state == .ended else {
            return
        }
        let velocity = gesture.velocity(in: _Container_image_view)
        let magnitude = sqrt((velocity.x * velocity.x) + (velocity.y * velocity.y))
        let slideMultiplier = magnitude / 200
        let slideFactor = 0.1 * slideMultiplier
        var finalPoint = CGPoint(
            x: gestureView.center.x + (velocity.x * slideFactor),
            y: gestureView.center.y + (velocity.y * slideFactor)
        )
        finalPoint.x = min(max(finalPoint.x, 0), _Container_image_view.bounds.width)
        finalPoint.y = min(max(finalPoint.y, 0), _Container_image_view.bounds.height)
        UIView.animate(
            withDuration: Double(slideFactor * 2),
            delay: 0,
            options: .curveEaseOut,
            animations: {
                gestureView.center = finalPoint
            })
    } 

Sorry, I don't understand your question. What does this code do?

this code works as keep the imagesticker always inside the viewcontainer

Simulator.Screen.Recording.-.iPhone.8.Plus.-.2022-05-18.at.13.43.01.mp4

I sent a message to whatsapp, did you receive it, I think it will be easier to communicate there