改变NSTextView中某一区域的鼠标手势

 文章来源:http://www.cocoachina.com/bbs/read.php?tid=52088

 

- (void)mouseMoved:(NSEvent *)theEvent   
{ 
    //- (NSPoint)locationInWindow 返回鼠标在当前窗口的坐标  
    //- (NSPoint)convertPoint:(NSPoint)aPoint fromView:(NSView *)aView 返回aPoint在aView坐标系中,调用者的相对坐标 
    NSPoint windowPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil]; 
    
    if ([self mouse:windowPoint inRect:rect]) //windowPoint是否在rect中 
    {  
        NSLog(@"YES!");   
        [self setSelectable:NO];            //关闭NSTextView的鼠标选择属性  
        [[NSCursor openHandCursor] set];    //将鼠标指针控制器设置为openHandCursor手势   
         
    }   
    else  
    {  
        NSLog(@"NO!"); 
        [self setSelectable:YES];        //打开NSTextView的鼠标选择属性 
        [self setEditable:YES];          //当NSTextView的鼠标选择属性关闭时,编辑属性也会一同被关闭,所以此处需要手动打开   
    }     
} 


 

你可能感兴趣的:(改变NSTextView中某一区域的鼠标手势)