mirror of
				https://github.com/laosb/CropImage.git
				synced 2025-10-31 14:21:38 +00:00 
			
		
		
		
	Allow zoom using scroll wheel
This commit is contained in:
		
							parent
							
								
									304a4c8e7e
								
							
						
					
					
						commit
						ea5a5354fb
					
				
					 1 changed files with 12 additions and 0 deletions
				
			
		|  | @ -81,6 +81,15 @@ struct UnderlyingImageView: View { | ||||||
|         scale = min(widthScale, heightScale) |         scale = min(widthScale, heightScale) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private func setupScrollMonitor() { | ||||||
|  |         #if os(macOS) | ||||||
|  |         NSEvent.addLocalMonitorForEvents(matching: .scrollWheel) {event in | ||||||
|  |             scale = scale + event.scrollingDeltaY/1000 | ||||||
|  |             return event | ||||||
|  |         } | ||||||
|  |         #endif | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     var imageView: Image { |     var imageView: Image { | ||||||
| #if os(macOS) | #if os(macOS) | ||||||
|         Image(nsImage: image) |         Image(nsImage: image) | ||||||
|  | @ -94,6 +103,9 @@ struct UnderlyingImageView: View { | ||||||
|             .gesture(dragGesture) |             .gesture(dragGesture) | ||||||
|             .gesture(magnificationgesture) |             .gesture(magnificationgesture) | ||||||
|             .gesture(rotationGesture) |             .gesture(rotationGesture) | ||||||
|  |             .onAppear { | ||||||
|  |                 setupScrollMonitor() | ||||||
|  |             } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     var dragGesture: some Gesture { |     var dragGesture: some Gesture { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ahnaf Mahmud
						Ahnaf Mahmud