ForgetSou | Blog

❤ 武统台湾 刻不容缓 ❤

0%

一. 简述

以可自定义的布局显示的数据项的有序集合。

@interface NSCollectionView : NSView

Merging content and layout to create the final appearance

二. 官方属性方法

// 为收集视图提供数据的对象
@property (nullable, weak) id<NSCollectionViewDataSource> dataSource API_AVAILABLE(macos(10.11));
@property (nullable, weak) id<NSCollectionViewPrefetching> prefetchDataSource API_AVAILABLE(macos(10.13));
// 委托对象
@property (nullable, weak) id<NSCollectionViewDelegate> delegate;
// 为收集视图提供数据的数组
@property (copy) NSArray<id> *content;
@property (nullable, strong) NSView *backgroundView API_AVAILABLE(macos(10.11));
// 背景色数组
@property (null_resettable, copy) NSArray<NSColor *> *backgroundColors;
// 背景视图是否随项目及其他内容滚动
@property BOOL backgroundViewScrollsWithContent API_AVAILABLE(macos(10.12));
// 构建集合视图内容的布局对象
@property (nullable, strong) __kindof NSCollectionViewLayout *collectionViewLayout API_AVAILABLE(macos(10.11));

!!! 之后再补充 !!!

三. 示例

1. 效果图

要达到的效果:

阅读全文 »

关闭/最小化/全屏居中处理(仿Mac QQ),效果如下

image-20201106143307906

WindowController中添加以下代码,直接复制到控制器并修改控制器名称就可以了。

//  FSWindowCtl.m
@interface FSWindowCtl ()<NSWindowDelegate>

@end

@implementation FSWindowCtl

- (void)windowDidLoad {
[super windowDidLoad];
[self settingWindowStyle];
}
// 设置window样式
- (void)settingWindowStyle {
self.window.titlebarAppearsTransparent = YES;
self.window.titleVisibility = NSWindowTitleHidden;
self.window.styleMask = NSWindowStyleMaskClosable | NSWindowStyleMaskResizable | NSWindowStyleMaskTitled | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskFullSizeContentView;
[self.window setMovableByWindowBackground:YES];
[self updateTitleBarOfWindow:NO];
}

// 修改关闭、最小化、全屏的位置
- (void)updateTitleBarOfWindow:(BOOL)fullScreen {
CGFloat kTitlebarH = 54.0;
CGFloat kFullScreenButtonYOrigin = 3.0;
NSRect windowFrame = self.window.frame;
NSView *titlebarContainerView = [self.window standardWindowButton:NSWindowCloseButton].superview.superview;
NSRect titlebarContainerFrame = titlebarContainerView.frame;
titlebarContainerFrame.origin.y = windowFrame.size.height - kTitlebarH;
titlebarContainerFrame.size.height = (CGFloat)kTitlebarH;
titlebarContainerView.frame = titlebarContainerFrame;

CGFloat buttonX = 12.0;
NSButton *closeBtn = [self.window standardWindowButton:NSWindowCloseButton];
NSButton *minimizeBtn = [self.window standardWindowButton:NSWindowMiniaturizeButton];
NSButton *zoomBtn = [self.window standardWindowButton:NSWindowZoomButton];

for (NSButton *buttonView in @[closeBtn, minimizeBtn, zoomBtn]) {
NSRect buttonFrame = buttonView.frame;
buttonFrame.origin.y = fullScreen ? kFullScreenButtonYOrigin : round((kTitlebarH - buttonFrame.size.height)/2.0);
buttonFrame.origin.x = (CGFloat)buttonX;
buttonX = buttonFrame.size.width + buttonX + 6;
[buttonView setFrameOrigin:buttonFrame.origin];
}
}

#pragma mark - NSWindowDelegate
- (void)windowDidEnterFullScreen:(NSNotification *)notification {
[self updateTitleBarOfWindow:YES];
}

- (void)windowDidExitFullScreen:(NSNotification *)notification {
[self updateTitleBarOfWindow:NO];
}

- (void)windowDidResize:(NSNotification *)notification {
[self updateTitleBarOfWindow:NO];
}

@end
阅读全文 »