mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-08 05:30:47 +00:00
Improve PagerNode sample project
This commit is contained in:
parent
1c6686e5d6
commit
1f55ef8945
@ -11,6 +11,6 @@
|
|||||||
|
|
||||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||||
|
|
||||||
@interface ViewController : ASViewController
|
@interface ViewController : ASViewController<ASPagerNode *>
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -15,9 +15,14 @@
|
|||||||
|
|
||||||
#import "PageNode.h"
|
#import "PageNode.h"
|
||||||
|
|
||||||
@interface ViewController () <ASPagerNodeDataSource>
|
static UIColor *randomColor() {
|
||||||
|
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
|
||||||
|
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
|
||||||
|
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
|
||||||
|
return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
|
||||||
|
}
|
||||||
|
|
||||||
- (ASPagerNode *)node;
|
@interface ViewController () <ASPagerNodeDataSource>
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -25,19 +30,30 @@
|
|||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init
|
||||||
{
|
{
|
||||||
if (!(self = [super initWithNode:[[ASPagerNode alloc] init]]))
|
self = [super initWithNode:[[ASPagerNode alloc] init]];
|
||||||
return nil;
|
if (self == nil) {
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
[self node].dataSource = self;
|
|
||||||
|
|
||||||
self.title = @"Pages";
|
self.title = @"Pages";
|
||||||
|
self.node.dataSource = self;
|
||||||
|
|
||||||
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(scrollToNextPage:)];
|
||||||
|
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Previous" style:UIBarButtonItemStylePlain target:self action:@selector(scrollToPreviousPage:)];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASPagerNode *)node
|
#pragma mark - Actions
|
||||||
|
|
||||||
|
- (void)scrollToNextPage:(id)sender
|
||||||
{
|
{
|
||||||
return (ASPagerNode *)[super node];
|
[self.node scrollToPageAtIndex:self.node.currentPageIndex+1 animated:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)scrollToPreviousPage:(id)sender
|
||||||
|
{
|
||||||
|
[self.node scrollToPageAtIndex:self.node.currentPageIndex-1 animated:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - ASPagerNodeDataSource
|
#pragma mark - ASPagerNodeDataSource
|
||||||
@ -47,11 +63,13 @@
|
|||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index
|
- (ASCellNodeBlock)pagerNode:(ASPagerNode *)pagerNode nodeBlockAtIndex:(NSInteger)index
|
||||||
{
|
{
|
||||||
PageNode *page = [[PageNode alloc] init];
|
return ^{
|
||||||
page.backgroundColor = [UIColor blueColor];
|
PageNode *page = [[PageNode alloc] init];
|
||||||
return page;
|
page.backgroundColor = randomColor();
|
||||||
|
return page;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user