: 특정 행 위로 마우스를 슬쩍은 행이 강조 될 때 , 그냥 "마우스 오버를 무시 버튼코코아의 tableView에 mouseOver 이벤트를 추가하는 방법이 있습니까?
1
나는이처럼 내있는 tableView 행동을 할
A
답변
1
(의 mouseOver 이벤트처럼 나쁜 GUI입니다
"설교 (어쨌든 무시할 것입니다 ...-))
#import "MoTableView.h"
@implementation MoTableView
{
NSUInteger mouseRow;
NSRect mouseRowFrame;
}
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
mouseRow = -1;
}
return self;
}
- (void)awakeFromNib
{
[self.window setAcceptsMouseMovedEvents:YES];
}
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
// Drawing code here.
[[NSColor redColor] set];
NSLogDebug(@"mouseRowFrame: %@", NSStringFromRect(mouseRowFrame));
NSFrameRectWithWidth(mouseRowFrame, 2.);
}
- (void)mouseMoved:(NSEvent *)theEvent
{
NSPoint mouseLocation = [theEvent locationInWindow];
NSPoint viewLocation = [self convertPoint:mouseLocation fromView:nil] ;
NSInteger row = [self rowAtPoint:viewLocation];
if (row != mouseRow) {
mouseRowFrame = [self rectOfRow:row];
[self setNeedsDisplay];
mouseRow = row;
}
}
@end
0
하위 클래스를 만들고 추적 영역을 사용해야합니다. 이것이 마우스 버튼을 추적하는 데 사용됩니다.
정확하게 당신이 필요하지 애플 샘플 코드있다 - 호버에 행을 강조 :
그것은 철저하게 WWDC 2011 Session 120
4
에서 논의 된 것 그것은 나에게 그것을 작동하는 데 시간이 걸렸다 기반 에힌트.
내가 틀렸다면 그것은 나를 위해 일하고, 나를 바로 잡습니다. 맥 OS 10.12.2와 엑스 코드 8.2.1
//
// Created by longkai on 30/12/2016.
// Copyright (c) 2016 xiaolongtongxue.com. All rights reserved.
//
import Cocoa
class InboxTableCellView: NSTableCellView {
// MARK: - Outlets
@IBOutlet weak var title: NSTextField!
@IBOutlet weak var sender: NSTextField!
@IBOutlet weak var time: NSTextField!
@IBOutlet weak var snippet: NSTextField!
// MARK: - Mouse hover
deinit {
removeTrackingArea(trackingArea)
}
private var trackingArea: NSTrackingArea!
override func awakeFromNib() {
super.awakeFromNib()
self.trackingArea = NSTrackingArea(
rect: bounds,
options: [NSTrackingAreaOptions.activeAlways, NSTrackingAreaOptions.mouseEnteredAndExited,/* NSTrackingAreaOptions.mouseMoved */],
owner: self,
userInfo: nil
)
addTrackingArea(trackingArea)
}
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
NSColor(red: 0.96, green: 0.96, blue: 0.96, alpha: 1.00).set()
// mouse hover
if highlight {
let path = NSBezierPath(rect: bounds)
path.fill()
}
// draw divider
let rect = NSRect(x: 0, y: bounds.height - 2, width: bounds.width, height: bounds.height)
let path = NSBezierPath(rect: rect)
path.fill()
}
private var highlight = false {
didSet {
setNeedsDisplay(bounds)
}
}
override func mouseEntered(with event: NSEvent) {
super.mouseEntered(with: event)
if !highlight {
highlight = true
}
}
override func mouseExited(with event: NSEvent) {
super.mouseExited(with: event)
if highlight {
highlight = false
}
}
}
+0
는 나에게 치료를했다 – joe
관련 문제
- 1. Ext.data.JsonStore에 mouseover 이벤트를 추가하는 방법은 무엇입니까?
- 2. 삽입 된 비디오의 mouseover 이벤트를 일시적으로 비활성화하는 방법이 있습니까?
- 3. ASP.NET Label 서버 컨트롤에 onclick 이벤트를 추가하는 방법이 있습니까?
- 4. 자바 스크립트 : 개체에서 모든 mouseover 이벤트를 제거하십시오.
- 5. viewDidUnload 이벤트를 트리거하는 방법이 있습니까?
- 6. window.open 이벤트를 제거하는 방법이 있습니까?
- 7. 코코아의 NSCell에서 텍스트와 아이콘을 결합하는 간단한 방법이 있습니까?
- 8. 리플릿에서 mouseover 이벤트를 활성화하기위한 임계 값 변경
- 9. Google지도 v3의 경로에 mouseover 이벤트를 추가하려면 어떻게해야하나요?
- 10. mouseover 이벤트를 모든 요소 또는 이미지에서만 사용할 수 있습니까?
- 11. 누구나 SVG에서 각도 ng-mouseover 이벤트를 수행하는 방법을 알고 있습니까?
- 12. TableFolumn을 JavaFX의 TableView에 동적으로 추가하는 방법은 무엇입니까?
- 13. appcelerator에서 TableView에 프로그래밍 방식으로 행을 추가하는 방법
- 14. jquery mouseover 및 mouseout 이벤트를 만들려고 시도합니다.
- 15. EaselJS에서 mouseover 이벤트를 처리하는 방법은 무엇입니까?
- 16. jquery의 행에 mouseover 이벤트를 추가하려면 어떻게해야합니까?
- 17. NavigationBar (NavigationController없이) 및 SearchBar를 TableView에 추가하는 방법
- 18. 스크롤하는 아이폰에서 tableview에 요소를 추가하는 방법은 무엇입니까?
- 19. UIButton 또는 UISwitch를 tableView에 추가하는 방법 : viewForFooterInSection
- 20. 동일한 UIViewController에서 두 TableView에 UISearchBar를 추가하는 방법
- 21. ios에서 tableview에 대한 행 줄을 추가하는 방법
- 22. Objective-C : thumbnail을 TableView에 추가하는 방법 비디오에서?
- 23. 코코아의 범주와 반대되는 것이 있습니까?
- 24. 코코아의 양방향지도
- 25. BatchWriteItems에 조건을 추가하는 방법이 있습니까?
- 26. Scrollorama에 여유를 추가하는 방법이 있습니까?
- 27. Cygwin에 암호를 추가하는 방법이 있습니까
- 28. 돼지에 datetime을 추가하는 방법이 있습니까?
- 29. pycparser에 키워드를 추가하는 방법이 있습니까?
- 30. iOS에서 addTarget 메서드를 UIImageView에 추가하는 방법이 있습니까?
내가 맥에 코코아 응용 프로그램에 대해서 이야기하고에 스위프트 3.0.2로 테스트
하지 IOS) : @iPatel – Edward