NSView | NSTextField右键问题
我有一个 NSView,里面有一个 Label : NSTextField Control, 在 NSView 内部,我必须在右键单击时显示一个上下文菜单,它工作正常,除了下面的几个问题,
在某些地方它不起作用,即如果我右键单击,它不会打开上下文菜单,进一步我意识到我保持标签的长度/宽度太大,并且在标签上单击鼠标右键, 但由于这是空白区域,因此根据用户体验,它应该允许打开上下文菜单,我觉得有两种方法可以解决此问题
1 - 检查 NSTextField 运行时的宽度/长度以设置正确的宽度,
2 - 将鼠标事件(或至少右键单击)从 NSTextField(标签)传递到其 ParentView,
任何人都可以建议我,我怎样才能实现这一点?
亲切的问候
罗汉
I have a NSView and inside that, there is a Label : NSTextField Control,
Inside NSView i have to show a context menu on the right click, its working fine except few below issue,
At some place it didn't work, i.e. if i do right click , it doesn't open the Context Menu, further i realized i have kept length/Width of Label is too big and right click happening over the Label,
but since this is the empty area, so as par user experience, it should allow to open the context menu, i feel following two approaches to solve this problem
1 -- Check the width/Length of the NSTextField runtime to set the proper width,
2 -- Pass Mouse event ( or at-least Right-click )from NSTextField( Label ) to its ParentView,
Can anyone suggest me, how can i achieve that ?
Kind Regards
Rohan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定这是否有帮助,但是当您在界面生成器中的 nstextfield 上单击鼠标右键时,您将看到一个“菜单”对象。将其与 NSMenu 连接,您将拥有一个默认的上下文菜单。
I'm not sure if this helps but when you click with the right mouse button on the nstextfield in the Interface Builder you'll see a "menu" object. Connecting this with a NSMenu and you have a default context menu.
到目前为止,它与以下代码一起工作,
-(void)initSubViews{
/* 在此函数中只需初始化子视图 */
NSSize imageSize = [pStatusImage 大小];
这样
我就可以在右键单击时看到菜单,
亲切的问候
罗汉
So far its working with following piece of code,
-(void)initSubViews{
/* In this function just init the sub-views */
NSSize imageSize = [pStatusImage size];
}
so i can able to see the menu on the right click,
Kind Regards
Rohan