Cocoa 用户可调整大小的视图
我如何实现像界面生成器中那样的用户可调整大小的视图,以便用户可以通过自己的
我是否必须使用监视鼠标移动等的视图来手动管理所有这些?
how can i achieve user-resizable views like in interface builder, so that the user can adjust some images by their own
Do i have to manage all this manually with a view that watches mouse movement and so on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你必须自己做所有的工作。您将需要跟踪视图中的对象及其位置,并进行所有鼠标跟踪和视图更新。
然而,这实际上并不是很困难,Apple 在其 草图示例代码。
You have to do all the work yourself. You will need to keep track of the objects in your view, their positions and do all the mouse tracking and view updating.
However, this is not actually very difficult, and Apple has provided a very complete example in its Sketch sample code.
我建议在您希望视图可调整大小的位置绘制一些按钮。然后开始跟踪视图中的鼠标事件。现在,当用户在单击某个位置时拖动鼠标时,只需相应地更改视图的框架即可。所有这些都应该可以在 NSView 的子类中实现。
I suggest drawing some buttons where you want the view to be resizable. Then start tracking mouse events in the view. Now, when a user drags its mouse while clicking on when of your spots, just change the view's frame accordingly. All of that should be possible to implement in a subclass of
NSView
.