// // KMCoverButton.m // PDF Reader // // Created by tangchao on 2022/2/24. // Copyright © 2022 Kdan Mobile. All rights reserved. // #import "KMCoverButton.h" @interface KMCoverButton () @property (nonatomic, strong) NSTrackingArea *area; @end @implementation KMCoverButton - (void)dealloc { [self removeTrackingArea:_area]; } - (void)updateTrackingAreas { [super updateTrackingAreas]; if (self.area) { [self removeTrackingArea:self.area]; self.area = nil; } int opts = (NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveAlways); self.area = [[NSTrackingArea alloc] initWithRect:self.bounds options:opts owner:self userInfo:nil]; [self addTrackingArea:self.area]; } - (void)mouseEntered:(NSEvent *)event { if (self.coverAction) { self.coverAction(self, KMCoverActionEnter); } } - (void)mouseExited:(NSEvent *)event { if (self.coverAction) { self.coverAction(self, KMCoverActionExit); } } - (void)mouseMoved:(NSEvent *)event { if (self.coverAction) { self.coverAction(self, KMCoverActionMove); } } @end