#import "ViewController.h"
@import QuartzCore;
#define kChildWindowH 76
@interface ViewController()
@property (nonatomic, strong) NSWindow *childWindow;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSButton *drawerButton = [[NSButton alloc] initWithFrame:NSMakeRect((self.view.bounds.size.width - 20) / 2.0, 20, 20, 20)];
[drawerButton setButtonType:NSToggleButton];
[drawerButton setBordered:NO];
[drawerButton setImage:[NSImage imageNamed:@"down"]];
[drawerButton setAlternateImage:[NSImage imageNamed:@"up"]];
[drawerButton setImagePosition:NSImageOnly];
[drawerButton setState:NSControlStateValueOff];
[drawerButton setTarget:self];
[drawerButton setAction:@selector(drawerButtonClick:)];
[self.view addSubview:drawerButton];
}
-(NSWindow *)childWindow
{
if (!_childWindow) {
NSRect rect = CGRectMake(self.view.window.frame.origin.x, self.view.window.frame.origin.y - kChildWindowH, self.view.window.frame.size.width, kChildWindowH);
_childWindow = [[NSWindow alloc] initWithContentRect:rect styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView backing:NSBackingStoreBuffered defer:NO];
_childWindow.titlebarAppearsTransparent = YES;
_childWindow.titleVisibility = NSWindowTitleHidden;
[self.view.window addChildWindow:_childWindow ordered:NSWindowBelow];
}
return _childWindow;
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
// Update the view, if already loaded.
}
- (void)drawerButtonClick:(id)sender {
NSButton *button = (NSButton *)sender;
if (button.state == NSOffState) { //隐藏
self.childWindow.hasShadow = NO;
[NSAnimationContext runAnimationGroup:^(NSAnimationContext * _Nonnull context) {
context.allowsImplicitAnimation = YES;
context.duration = 0.3;
context.timingFunction = [CAMediaTimingFunction functionWithName:@"easeOut"];
NSRect rect = [self contentWindowFrameWithclosed:YES];
[self.childWindow setFrame:rect display:YES];
} completionHandler:^{
}];
}
else { //显示
[NSAnimationContext runAnimationGroup:^(NSAnimationContext * _Nonnull context) {
context.allowsImplicitAnimation = YES;
context.duration = 0.3;
context.timingFunction = [CAMediaTimingFunction functionWithName:@"easeIn"];
NSRect rect = [self contentWindowFrameWithclosed:NO];
[self.childWindow setFrame:rect display:YES];
} completionHandler:^{
self.childWindow.hasShadow = YES;
}];
}
}
- (NSRect)contentWindowFrameWithclosed:(BOOL)bClosed
{
NSRect rectClose = NSZeroRect;
NSRect parentFrame = self.view.window.frame;
NSRect contentFrame = NSMakeRect(0, 0, self.view.window.frame.size.width, kChildWindowH + 22);
NSRect fixRect = NSInsetRect(parentFrame, 0.5 * (NSWidth(parentFrame) - NSWidth(contentFrame)), 0.5 * (NSHeight(parentFrame) - NSHeight(contentFrame)));
fixRect.origin.y = NSMinY(parentFrame) - (!bClosed ? NSHeight(contentFrame) - 22 : 0);
rectClose = fixRect;
return rectClose;
}
@end
MAC开发--仿QQ登录界面的下拉式抽屉效果
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 引子 一直认为Mac QQ的登录界面清爽节约,体验很不错,所以想着是怎么实现的,周末花了点时间把它实现了一下。源码...
- 百度网盘链接: https://pan.baidu.com/s/1o7GIkhO 密码: c9ka 附上一张效果图
- 现在QQ不是可以同时登录多个账号吗?怎么才能实现QQ这种效果,开启多个哪?下面我们就来探讨一下。 1、在Main....
- github地址:https://github.com/LYM-mg/MGSlideViewDemo 废话不多说,...