我对一个自定义视图进行了子类化,并将其拖入 Interface Builder 的窗口中。当鼠标进入视图的边界时,我想改变视图的高度。我的问题是高度变化是向上而不是向下。我尝试翻转视图的坐标,(BOOL)isFlipped
但它对高度变化的方向没有任何影响。关于如何改变向下方向的高度有什么帮助吗?
#import "ViewA.h"
@implementation ViewA
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
options:(NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways)
owner:self
userInfo:nil];
[self addTrackingArea:trackingArea];
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
[[NSColor redColor] setFill];
NSRectFill(dirtyRect);
}
- (BOOL)isFlipped {
return YES;
}
- (void)mouseEntered:(NSEvent *)theEvent {
NSRect rect = self.frame;
rect.size.height = 120;
self.frame = rect;
}
- (void)mouseExited:(NSEvent *)theEvent {
NSRect rect = self.frame;
rect.size.height = 90;
self.frame = rect;
}
@end