1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- //
- // 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
|