#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登录界面的下拉式抽屉效果
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 引子 一直认为Mac QQ的登录界面清爽节约,体验很不错,所以想着是怎么实现的,周末花了点时间把它实现了一下。源码...
- 百度网盘链接: https://pan.baidu.com/s/1o7GIkhO 密码: c9ka 附上一张效果图
- 现在QQ不是可以同时登录多个账号吗?怎么才能实现QQ这种效果,开启多个哪?下面我们就来探讨一下。 1、在Main....
- github地址:https://github.com/LYM-mg/MGSlideViewDemo 废话不多说,...