PaperKit 0.8.1

PaperKit 0.8.1

测试已测试
语言语言 Obj-CObjective C
许可 BSD
发布最后发布2016年4月

1amageek 维护。




PaperKit 0.8.1

PaperKit 是一个框架,可以轻松创建 Facebook 的 Paper。它可以用于操作 UIKit 的CollectionView。

sample

试例

要求:Xcode7 beta4

$ pod try PaperKit

或者,通过 appetize.io

快速开始

PaperKit 可在 CocoaPods 上使用。将以下内容添加到您的 Podfile 中

pod 'PaperKit'

导入框架头文件,如果您使用 Swift,请创建一个 Objective-C 互用头文件

#import <PaperKit/PaperKit.h>

继承 PKViewController

@interface ViewController : PKViewController

用法

PKViewController

其中包含多个CollectionView。要控制各自的 CollectionViewController,请重写以下方法。

- (NSInteger)backgroundCollectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    // override method
    return 10;
}

- (NSInteger)foregroundCollectionVew:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section onCategory:(NSInteger)category
{
    // override method
    return 10;
}
- (UICollectionViewCell *)backgroundCollectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    CGFloat color = floorf(indexPath.item)/[self backgroundCollectionView:collectionView numberOfItemsInSection:indexPath.section];
    cell.backgroundColor = [UIColor colorWithHue:color saturation:1 brightness:1 alpha:1];
    return cell;
}

- (PKContentViewController *)foregroundCollectionView:(PKCollectionView *)collectionView contentViewControllerForAtIndexPath:(NSIndexPath *)indexPath onCategory:(NSUInteger)category
{
    NSLog(@"indexPaht %@ cateogry %lu",indexPath, (unsigned long)category);
    return [ContentViewController new];
}

您可以使用该方法进行数据源重新加载。此方法在您在滚动视图的内容大小之外拖动时调用。

- (void)scrollView:(UIScrollView *)scrollView slideToAction:(PKCollectionViewControllerScrollDirection)direction;
{
    if (direction == PKCollectionViewControllerScrollDirectionPrevious) {
        NSLog(@"PKCollectionViewControllerScrollDirectionPrevious");
    } else {
        NSLog(@"PKCollectionViewControllerScrollDirectionNext");
    }
}

要重新加载数据源,运行以下方法。

// backgroundCollectionView dataSource reload
[self reloadBackgroundData];

// foregroundCollectionView dataSource reload
[self reloadForegroundDataOnCategory:self.selectedCategory];

PKWindow

PKWindow 可以按层次结构排列 Window。PKWindow 由 PKWindowManager 管理。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    BackgroundViewController *backgroundViewController = [BackgroundViewController new];
    self.window.rootViewController = backgroundViewController;
    [self.window makeKeyAndVisible];

    [PKWindowManager managerWithBaseWindow:self.window];

    return YES;
}

通过传递 RootViewController 给 PKWindowManager 来创建新窗口。

ViewController *nextViewController = [ViewController new];
[[PKWindowManager sharedManager] showWindowWithRootViewController:nextViewController];

了解更多信息