basic mouse event

mouse down, mouse dragging, mouse up, and mouse movement.

responder chain

views next responder is its super view
generally a view insert into a view hierarchy ,this view is automatically as its subView’s next responder
never call setNextResponder method

firstResponder

如果一个view作为firstResponder 则这个view会先于其他对象接受到他们发送消息的回应
通常表现比如文本框如果作为firstResponder就会有竖杠闪烁

general view only receive mousedown message which is not as firstResponde,但是这个view必须显示window上 并且是可见的
比如某个文本框并不是firstResponder,但是如果他被鼠标点击了 它就会作为firstResponder,所以它接受到了mouseDown

成为firstReponder

view.window makeFirstResponder:一个NSView或者NSTextField
//方法
[NSTestField becomeFirstResponder];//不建议这样调用

element调用这个方法并不是一定生效,调用后首先会询问当前first responder 让他resign,如果他同意了那会再查看一下目标elementcanBecomeFirstResponder 如果可以然后会再查看这个element是否active view hierarchy(如果element所属的window是一个valid window 则表示是在active view hierarchy) 这样才会将element置为first responder
这个responder cainroot 一般是applicationkey Window

一般是子类重写becomeFirstResponder方法里面添加text filer的修饰 实现highlighting

acceptsFirstResponder

default NSResponder instance return NO
you can override this method

- (BOOL)acceptsFirstResponder
{
    return YES;
}

becomeFirstResponder

if a view receive this message ,is mean that window attemps to make the view first responder,default implementation this message return YES

resignFirstResponder

if you want to resign a view as firstResponder call this message

key view loop

key view loop let user can user presstabkeys switch between views in a window
so if a view can become firstResponder ,this view must in key view loop
you can set a view as other view’s next key view by setting view’snextKeyView

targetaction paradigm

控件向目标对象发送相应用户操作操作信息 比如说一个按钮 单击该按钮会将操作消息发送到按钮的目标对象 如果未指定特定的目标对象 则会将其发送响应者链的上游

获取鼠标点击位置

通过locationInWindow获取鼠标点击window的坐标,再通过convertPoint转换到view坐标系

-(void)mouseDown:(NSEvent *)event
{
    NSPoint clickLocation;
	clickLocation = [self convertPoint:[event locationInWindow]
                  fromView:nil];
}

关于自己实现mouseMove这些message看这里

苹果开发文档

原文地址:https://blog.csdn.net/qq_43535469/article/details/129638075

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_38736.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注