mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-17 11:50:56 +00:00
Overall examples improvement
This commit is contained in:
parent
6bf150bc65
commit
bb35470c72
@ -18,6 +18,7 @@
|
|||||||
- (void)viewDidLoad
|
- (void)viewDidLoad
|
||||||
{
|
{
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|
||||||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push Details" style:UIBarButtonItemStylePlain target:self action:@selector(pushNewViewController)];
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push Details" style:UIBarButtonItemStylePlain target:self action:@selector(pushNewViewController)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,9 +17,11 @@
|
|||||||
|
|
||||||
static CGFloat kInsets = 15.0;
|
static CGFloat kInsets = 15.0;
|
||||||
|
|
||||||
@implementation SupplementaryNode {
|
@interface SupplementaryNode ()
|
||||||
ASTextNode *_textNode;
|
@property (nonatomic, strong) ASTextNode *textNode;
|
||||||
}
|
@end
|
||||||
|
|
||||||
|
@implementation SupplementaryNode
|
||||||
|
|
||||||
- (instancetype)initWithText:(NSString *)text
|
- (instancetype)initWithText:(NSString *)text
|
||||||
{
|
{
|
||||||
@ -37,7 +39,7 @@ static CGFloat kInsets = 15.0;
|
|||||||
{
|
{
|
||||||
ASCenterLayoutSpec *center = [[ASCenterLayoutSpec alloc] init];
|
ASCenterLayoutSpec *center = [[ASCenterLayoutSpec alloc] init];
|
||||||
center.centeringOptions = ASCenterLayoutSpecCenteringXY;
|
center.centeringOptions = ASCenterLayoutSpecCenteringXY;
|
||||||
center.child = _textNode;
|
center.child = self.textNode;
|
||||||
UIEdgeInsets insets = UIEdgeInsetsMake(kInsets, kInsets, kInsets, kInsets);
|
UIEdgeInsets insets = UIEdgeInsetsMake(kInsets, kInsets, kInsets, kInsets);
|
||||||
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:center];
|
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:center];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,50 +15,48 @@
|
|||||||
#import "SupplementaryNode.h"
|
#import "SupplementaryNode.h"
|
||||||
#import "ItemNode.h"
|
#import "ItemNode.h"
|
||||||
|
|
||||||
|
@interface ViewController ()
|
||||||
|
@property (nonatomic, strong) ASCollectionView *collectionView;
|
||||||
|
@property (nonatomic, strong) NSArray *data;
|
||||||
|
@end
|
||||||
|
|
||||||
@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout>
|
@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout>
|
||||||
{
|
|
||||||
ASCollectionView *_collectionView;
|
|
||||||
NSArray *_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation ViewController
|
@implementation ViewController
|
||||||
|
|
||||||
#pragma mark -
|
- (void)dealloc
|
||||||
#pragma mark UIViewController.
|
|
||||||
|
|
||||||
- (instancetype)init
|
|
||||||
{
|
{
|
||||||
if (!(self = [super init]))
|
self.collectionView.asyncDataSource = nil;
|
||||||
return nil;
|
self.collectionView.asyncDelegate = nil;
|
||||||
|
|
||||||
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
NSLog(@"ViewController is deallocing");
|
||||||
layout.headerReferenceSize = CGSizeMake(50.0, 50.0);
|
|
||||||
layout.footerReferenceSize = CGSizeMake(50.0, 50.0);
|
|
||||||
|
|
||||||
_collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
||||||
_collectionView.asyncDataSource = self;
|
|
||||||
_collectionView.asyncDelegate = self;
|
|
||||||
_collectionView.backgroundColor = [UIColor whiteColor];
|
|
||||||
|
|
||||||
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
|
|
||||||
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter];
|
|
||||||
|
|
||||||
#if !SIMULATE_WEB_RESPONSE
|
|
||||||
self.navigationItem.leftItemsSupplementBackButton = YES;
|
|
||||||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadTapped)];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidLoad
|
- (void)viewDidLoad
|
||||||
{
|
{
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|
||||||
[self.view addSubview:_collectionView];
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||||||
|
layout.headerReferenceSize = CGSizeMake(50.0, 50.0);
|
||||||
|
layout.footerReferenceSize = CGSizeMake(50.0, 50.0);
|
||||||
|
|
||||||
|
self.collectionView = [[ASCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
|
||||||
|
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||||
|
self.collectionView.asyncDataSource = self;
|
||||||
|
self.collectionView.asyncDelegate = self;
|
||||||
|
self.collectionView.backgroundColor = [UIColor whiteColor];
|
||||||
|
|
||||||
|
[self.collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
|
||||||
|
[self.collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter];
|
||||||
|
[self.view addSubview:self.collectionView];
|
||||||
|
|
||||||
|
#if !SIMULATE_WEB_RESPONSE
|
||||||
|
self.navigationItem.leftItemsSupplementBackButton = YES;
|
||||||
|
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadTapped)];
|
||||||
|
#endif
|
||||||
|
|
||||||
#if SIMULATE_WEB_RESPONSE
|
#if SIMULATE_WEB_RESPONSE
|
||||||
__weak typeof(self) weakSelf = self;
|
__weak typeof(self) weakSelf = self;
|
||||||
@ -86,11 +84,6 @@
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewWillLayoutSubviews
|
|
||||||
{
|
|
||||||
_collectionView.frame = self.view.bounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)prefersStatusBarHidden
|
- (BOOL)prefersStatusBarHidden
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
@ -98,7 +91,7 @@
|
|||||||
|
|
||||||
- (void)reloadTapped
|
- (void)reloadTapped
|
||||||
{
|
{
|
||||||
[_collectionView reloadData];
|
[self.collectionView reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
@ -116,11 +109,8 @@
|
|||||||
{
|
{
|
||||||
NSString *text = [kind isEqualToString:UICollectionElementKindSectionHeader] ? @"Header" : @"Footer";
|
NSString *text = [kind isEqualToString:UICollectionElementKindSectionHeader] ? @"Header" : @"Footer";
|
||||||
SupplementaryNode *node = [[SupplementaryNode alloc] initWithText:text];
|
SupplementaryNode *node = [[SupplementaryNode alloc] initWithText:text];
|
||||||
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
|
BOOL isHeaderSection = [kind isEqualToString:UICollectionElementKindSectionHeader];
|
||||||
node.backgroundColor = [UIColor blueColor];
|
node.backgroundColor = isHeaderSection ? [UIColor blueColor] : [UIColor redColor];
|
||||||
} else {
|
|
||||||
node.backgroundColor = [UIColor redColor];
|
|
||||||
}
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,15 +145,9 @@
|
|||||||
[context completeBatchFetching:YES];
|
[context completeBatchFetching:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (UIEdgeInsets)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
|
- (UIEdgeInsets)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
|
||||||
|
{
|
||||||
return UIEdgeInsetsMake(20.0, 20.0, 20.0, 20.0);
|
return UIEdgeInsetsMake(20.0, 20.0, 20.0, 20.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SIMULATE_WEB_RESPONSE
|
|
||||||
-(void)dealloc
|
|
||||||
{
|
|
||||||
NSLog(@"ViewController is deallocing");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -34,8 +34,8 @@ static NSUInteger kNumberOfImages = 14;
|
|||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init
|
||||||
{
|
{
|
||||||
if (!(self = [super init]))
|
self = [super init];
|
||||||
return nil;
|
if (self) {
|
||||||
|
|
||||||
_sections = [NSMutableArray array];
|
_sections = [NSMutableArray array];
|
||||||
[_sections addObject:[NSMutableArray array]];
|
[_sections addObject:[NSMutableArray array]];
|
||||||
@ -48,20 +48,7 @@ static NSUInteger kNumberOfImages = 14;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MosaicCollectionViewLayout *layout = [[MosaicCollectionViewLayout alloc] init];
|
}
|
||||||
layout.numberOfColumns = 2;
|
|
||||||
layout.headerHeight = 44.0;
|
|
||||||
|
|
||||||
_layoutInspector = [[MosaicCollectionViewLayoutInspector alloc] init];
|
|
||||||
|
|
||||||
_collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout asyncDataFetching:YES];
|
|
||||||
_collectionView.asyncDataSource = self;
|
|
||||||
_collectionView.asyncDelegate = self;
|
|
||||||
_collectionView.layoutInspector = _layoutInspector;
|
|
||||||
_collectionView.backgroundColor = [UIColor whiteColor];
|
|
||||||
|
|
||||||
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,12 +56,27 @@ static NSUInteger kNumberOfImages = 14;
|
|||||||
{
|
{
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|
||||||
|
MosaicCollectionViewLayout *layout = [[MosaicCollectionViewLayout alloc] init];
|
||||||
|
layout.numberOfColumns = 2;
|
||||||
|
layout.headerHeight = 44.0;
|
||||||
|
|
||||||
|
_layoutInspector = [[MosaicCollectionViewLayoutInspector alloc] init];
|
||||||
|
|
||||||
|
_collectionView = [[ASCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
|
||||||
|
_collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
|
||||||
|
_collectionView.asyncDataSource = self;
|
||||||
|
_collectionView.asyncDelegate = self;
|
||||||
|
_collectionView.layoutInspector = _layoutInspector;
|
||||||
|
_collectionView.backgroundColor = [UIColor whiteColor];
|
||||||
|
|
||||||
|
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
|
||||||
[self.view addSubview:_collectionView];
|
[self.view addSubview:_collectionView];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewWillLayoutSubviews
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
_collectionView.frame = self.view.bounds;
|
_collectionView.asyncDataSource = nil;
|
||||||
|
_collectionView.asyncDelegate = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)prefersStatusBarHidden
|
- (BOOL)prefersStatusBarHidden
|
||||||
@ -109,11 +111,13 @@ static NSUInteger kNumberOfImages = 14;
|
|||||||
return [[SupplementaryNode alloc] initWithText:text];
|
return [[SupplementaryNode alloc] initWithText:text];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
||||||
|
{
|
||||||
return _sections.count;
|
return _sections.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||||
|
{
|
||||||
return [_sections[section] count];
|
return [_sections[section] count];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -65,6 +65,12 @@ static NSUInteger kNumberOfImages = 14;
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
_collectionView.asyncDataSource = nil;
|
||||||
|
_collectionView.asyncDelegate = nil;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)viewDidLoad
|
- (void)viewDidLoad
|
||||||
{
|
{
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user