Skip to content

Conversation

@navanchauhan
Copy link

  • Adds internal typealias PlatformImage that uses UIKit or AppKit depending on what it can import
  • Correctly applies UIKit/AppKit function
  • Adds support for macOS to the demo (tested as well)

Theoretically, magnification and rotation should work on macOS but doesn't for some reason (and doesn't throw any errors either). I might update both gesture to their newer counterparts

@navanchauhan
Copy link
Author

Welp. This is randomly working/not-working. I need to investigate a bit more

@navanchauhan
Copy link
Author

I think the issue of sometimes working is already addressed in the README and was discussed in #13

Two solutions I have come up with to enable zoom on macOS:

  • Manual scroll wheel event handler
    private func handleScrollEvent(_ event: NSEvent) {        
        let currentTime = Date()
        let timeDifference = currentTime.timeIntervalSince(lastScrollTime)
        
        if timeDifference > 0.1 {
            scrollMagnitude = 0
        }
        
        scrollMagnitude += event.deltaY
        
        let scaleFactor: CGFloat = 1 + (scrollMagnitude * 0.001)
        handleMagnification(value: MagnificationGesture.Value(scaleFactor))
        
        viewModel.lastScale = viewModel.scale
        viewModel.lastOffset = viewModel.offset
        
        lastScrollTime = currentTime
    }
  • Add Command + and Command - shortcut
    private func handleKeyEvent(_ event: NSEvent) {
        if event.modifierFlags.contains(.command) {
            switch event.keyCode {
            case 24: // Command +
                handleMagnification(value: MagnificationGesture.Value(1.1))
                viewModel.lastScale = viewModel.scale
                viewModel.lastOffset = viewModel.offset
            case 27: // Command -
                handleMagnification(value: MagnificationGesture.Value(0.9))
                viewModel.lastScale = viewModel.scale
                viewModel.lastOffset = viewModel.offset
            default:
                break
            }
        }
    }

@benedom
Copy link
Owner

benedom commented Aug 14, 2024

Thanks for the PR and effort @navanchauhan! I've been pretty busy these past days but I will take a detailed look at your code and test it soon!

@benedom
Copy link
Owner

benedom commented Aug 14, 2024

@navanchauhan I have another suggestion how to solve the zooming issue on Mac:

  • Maybe showing buttons (e.g. "+" and "-") when cropping an image to zoom accordingly is easiest.

Especially since it is intuitive. As a user I might not be familiar with the cmd option and also not have a mouse wheel. This might be the easiest solution to the issue. What do you think?

@benedom benedom added the enhancement New feature or request label Aug 14, 2024
@benedom benedom linked an issue Aug 14, 2024 that may be closed by this pull request
@benedom benedom mentioned this pull request Aug 17, 2024
@navanchauhan
Copy link
Author

That is a really good suggestion. While I am at it, I might even add buttons for rotating the image

@navanchauhan
Copy link
Author

I was able to fix the issue where the circular crop was not working properly on macOS. Now, I just need to add buttons and clean up the code a bit.

I should have time this next week (or this weekend itself) to clean up and commit

@benedom
Copy link
Owner

benedom commented Jun 3, 2025

@navanchauhan hey it's been a while 😅 any update on your behalf for this issue?

@navanchauhan
Copy link
Author

I completely forgot about this. I just saw this while cleaning up my inbox...

Let me resurrect this PR and try to find some time next week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mac support

2 participants