由 NSSlider 控制的 IKImageView 缩放
通过 NSSlider 在 IKImageView 中设置图像缩放系数的最佳实践是什么?
我能够将滑块绑定到 IKImageView 的放大或缩小操作。 显然,我更愿意看到的是一个控制这两个操作的滑块。 最好,如果每次更改滑块后图像都会刷新(即使尚未释放鼠标按钮,也会持续刷新)。
What's the best practice for setting zoom factor of an image within IKImageView via NSSlider?
I was able to bind a slider either to zoom in OR zoom out action of an IKImageView.
Obviously, what I'd rather see is a single slider controlling both those actions.
Best, if image is refreshed after each change of the slider (continuously, even if a mouse button is not released yet).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个演示解释了很多: ImageKitDemo
特别是,这个片段正是我正在寻找的:
This demo explains a lot: ImageKitDemo
In particular, this snippet is what I was looking for:
绑定方式是将 IK 图像视图的缩放系数和滑块的值绑定到控制器的同一属性。当滑块更改属性值时,图像视图将收到通知,并从控制器获取新值。
这种方式的优点之一是您可以添加更多放大和缩小的方式,并且滑块中的值不会过时。举个例子,如果 IKImageView 添加了捏缩放功能(或者如果它已经有了——我的 Mac 上没有多点触控),则用户可以以这种方式缩放,并且滑块将自动更新。使用
IBAction
解决方案就不会发生这种情况。另一个例子是放大和缩小菜单命令(可能使用 ⌘+ 和 ⌘- 键盘快捷键),它们将操作消息发送到控制器。您的控制器将通过增加或减少属性的值(使用它实现的 setter 方法)来响应。使用绑定,图像视图和滑块都将免费更新。如果没有绑定,您将必须显式地与图像视图和滑块对话,告诉一个更新其缩放系数,另一个更新其滑块。
第三个例子是“缩放系数:X%”显示在窗口的一角。使用绑定,无论用户如何缩放图像:移动滑块拇指、捏合/松开图像或按下菜单项,都可以免费更新。如果没有绑定,这将是您在(至少三个)更改缩放值操作方法中必须讨论的另一件事。
The Bindings way would be to bind both the Zoom Factor of the IK image view and the Value of the slider to the same property of your controller. When the slider changes the value of the property, the image view will be notified, and will go get the new value from your controller.
One advantage of this way is that you can add more ways of zooming in and out and the value in the slider won't go stale. For one example, if IKImageView adds pinch-zooming (or if it has it already—I don't have multi-touch on my Mac), the user can zoom that way and the slider will update automatically. That won't happen with the
IBAction
solution.Another example would be Zoom In and Zoom Out menu commands (perhaps with ⌘+ and ⌘- keyboard shortcuts) that send action messages to your controller. Your controller would respond by increasing or decreasing the value of the property (using a setter method it implements). With Bindings, both the image view and the slider will update for free. Without Bindings, you would have to explicitly talk to both the image view and the slider, telling one to update its zoom factor and the other to update its slider.
A third example would be a “Zoom factor: X%” display in a corner of your window. With Bindings, this can update for free no matter how the user zooms the image: moving the slider thumb, pinching/unpinching the image, or pressing a menu item. Without Bindings, this would be yet another thing you have to talk to in your (at least three) change-the-zoom-value action methods.