OK. Итак, я думал об этом снова и снова, и вот что мне удалось; категория в NSView для переключения видов ...: -)
Заголовок:
#import <AppKit/AppKit.h>
#define DIRECTION_UP 0
#define DIRECTION_RIGHT 1
#define DIRECTION_DOWN 2
#define DIRECTION_LEFT 3
@interface NSView (NSView_Functions)
- (void)toggleWithView:(NSView*)mainView usingDirection:(int)direction;
@end
Реализация:
#import "NSView+Functions.h"
@implementation NSView (NSView_Functions)
- (void)toggleWithView:(NSView*)mainView usingDirection:(int)direction
{
NSRect mr = [mainView frame];
NSRect sr = [self frame];
#ifdef DEBUG
NSLog(@"MR @ %f,%f (%f X %f)",mr.origin.x,mr.origin.y,mr.size.width,mr.size.height);
NSLog(@"SR @ %f,%f (%f X %f)",sr.origin.x,sr.origin.y,sr.size.width,sr.size.height);
#endif
NSRect newMr;
CGFloat newX;
CGFloat newY;
CGFloat newWidth;
CGFloat newHeight;
switch (direction) {
case DIRECTION_RIGHT:
newX = mr.origin.x;
newY = mr.origin.y;
newHeight = mr.size.height;
if (![self isHidden]) newWidth = mr.size.width + sr.size.width;
else newWidth = mr.size.width - sr.size.width;
break;
case DIRECTION_DOWN:
newX = mr.origin.x;
newWidth = mr.size.width;
if (![self isHidden])
{
newY = mr.origin.y-sr.size.height;
newHeight = mr.size.height+sr.size.height;
}
else {
newY = mr.origin.y+sr.size.height;
newHeight = mr.size.height-sr.size.height;
}
break;
case DIRECTION_LEFT:
newY = mr.origin.y;
newHeight = mr.size.height;
if (![self isHidden])
{
newX = mr.origin.x-sr.size.width;
newWidth = mr.size.width+sr.size.width;
}
else {
newX = mr.origin.x+sr.size.width;
newWidth = mr.size.width-sr.size.width;
}
break;
case DIRECTION_UP:
newX = mr.origin.x;
newY = mr.origin.y;
newWidth = mr.size.width;
if (![self isHidden]) newHeight = mr.size.height + sr.size.height;
else newHeight = mr.size.height - sr.size.height;
break;
default:
break;
}
newMr = NSMakeRect(newX,newY,newWidth,newHeight);
if (![self isHidden]) [self setHidden:YES]; else [self setHidden:NO];
[mainView setFrame:newMr];
}
@end