NSImageView Unproportional Zoom

2017-02-10
#swift #nsimageview #appkit

I had this weird problem when I tried to implement a zoom functionality in my hobby project, a manga reader called Yomu. When I tried to zoom an NSImageView programmatically it's being zoomed unproportionally, my expectation was the image should be stretched horizontally and vertically without moving from its center point. It was like this

Zoom 100%

NSImageView unproportional zoom

Zoom 140%

NSImageView unproportional zoom

Damn, there was an ugly gap :( between header border and the image. I had a hard time finding the solution, it took me almost 3 days to debug this problem (maybe because I'm a newbie). It turns out the solution is really simple, by default apple will set image view to scale proportionally down, changing it to proportionally up or down will fix the problem.

The culprit T_T

NSImageView unproportional zoom

Fixing it 🍻

NSImageView unproportional zoom

Topics that might interest you