@@ -120,23 +120,17 @@ - (void)viewDidLoad {
120
120
[super viewDidLoad ];
121
121
self.clearsSelectionOnViewWillAppear = NO ;
122
122
123
+ [self updateCollectionViewLayoutConfiguration ];
124
+
123
125
self.collectionView .contentInset = UIEdgeInsetsMake (44 , 44 , 44 , 44 );
124
126
// self.collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(14, 0, 14, 0);
125
- [self .blCollectionViewLayout registerClass: BLDecorationView.class forDecorationViewOfKind: BLCollectionElementKindSectionDecoration];
126
- [self .blCollectionViewLayout
127
- autoConfigSystemAdditionalAdjustedContentInsetWith: UIApplication.sharedApplication.statusBarFrame
128
- navigationBar: self .navigationController.navigationBar
129
- tabbar: self .tabBarController.tabBar];
130
-
131
127
[self .collectionView registerClass: UICollectionReusableView.class
132
128
forSupplementaryViewOfKind: UICollectionElementKindSectionHeader withReuseIdentifier: UICollectionElementKindSectionHeader];
133
129
[self .collectionView registerClass: UICollectionReusableView.class
134
130
forSupplementaryViewOfKind: UICollectionElementKindSectionFooter withReuseIdentifier: UICollectionElementKindSectionFooter];
135
131
NSMutableArray *array = @[].mutableCopy ;
136
132
for (unichar var = ' A' ; var <= ' Z' ; var++) {
137
- NSString *text =
138
- [NSString stringWithCharacters: &var length: 1 ];
139
- [array addObject: text];
133
+ [array addObject: [NSString stringWithCharacters: &var length: 1 ]];
140
134
}
141
135
self.alphabetArray = array.copy ;
142
136
self.dataSource = @[self .alphabetArray.mutableCopy].mutableCopy ;
@@ -145,45 +139,44 @@ - (void)viewDidLoad {
145
139
[self add: nil ];
146
140
[self add: nil ];
147
141
[self add: nil ];
142
+ if (!self.navigationController ) {
143
+ self.navigationBar .hidden = NO ;
144
+ }
148
145
}
149
- - (void )viewWillAppear : (BOOL )animated
150
- {
151
- [super viewWillAppear: animated];
152
- if (self.navigationController ) return ;
153
- self.navigationBar .hidden = NO ;
154
- }
155
- - (void )viewWillDisappear : (BOOL )animated
146
+ - (void )updateCollectionViewLayoutConfiguration
156
147
{
157
- [super viewWillDisappear: animated];
158
- if (self.navigationController ) return ;
159
- self.navigationBar .hidden = YES ;
148
+ self.blCollectionViewLayout .elementAppearingAnimationFromValue =
149
+ ^UICollectionViewLayoutAttributes * _Nullable (UICollectionViewLayoutAttributes * _Nullable originalLayoutAttributes) {
150
+ originalLayoutAttributes.alpha = 0.1 ;
151
+ return originalLayoutAttributes;
152
+ };
153
+ self.blCollectionViewLayout .elementDisappearingAnimationToValue =
154
+ ^UICollectionViewLayoutAttributes * _Nullable (UICollectionViewLayoutAttributes * _Nullable originalLayoutAttributes) {
155
+ originalLayoutAttributes.alpha = 0.1 ;
156
+ return originalLayoutAttributes;
157
+ };
158
+ [self .blCollectionViewLayout registerClass: BLDecorationView.class forDecorationViewOfKind: BLCollectionElementKindSectionDecoration];
159
+ [self .blCollectionViewLayout
160
+ autoConfigSystemAdditionalAdjustedContentInsetWith: UIApplication.sharedApplication.statusBarFrame
161
+ navigationBar: self .navigationController.navigationBar
162
+ tabbar: self .tabBarController.tabBar];
160
163
}
161
-
162
164
- (UINavigationBar *)navigationBar
163
165
{
164
- if (self.navigationController ) return nil ;
165
166
if (!_navigationBar) {
166
167
UINavigationItem *item = UINavigationItem.new ;
167
- item.title = @" Fake NavigationBar" ;
168
168
item.leftBarButtonItems =
169
169
@[
170
170
[[UIBarButtonItem alloc ] initWithBarButtonSystemItem: UIBarButtonSystemItemAdd target: self action: @selector (add: )],
171
- [[UIBarButtonItem alloc ] initWithTitle: @" - " style: UIBarButtonItemStyleDone target: self action: @selector (delete : )],
171
+ [[UIBarButtonItem alloc ] initWithBarButtonSystemItem: UIBarButtonSystemItemTrash target: self action: @selector (add : )],
172
172
[[UIBarButtonItem alloc ] initWithBarButtonSystemItem: UIBarButtonSystemItemRefresh target: self action: @selector (refresh: )]
173
173
];
174
174
item.rightBarButtonItems =
175
175
@[
176
- [[UIBarButtonItem alloc ] initWithTitle: @" Decoration" style: UIBarButtonItemStyleDone target: self action: @selector (showDecoration: )],
177
- [[UIBarButtonItem alloc ] initWithTitle: @" UnPin" style: UIBarButtonItemStyleDone target: self action: @selector (unPin: )],
178
- [[UIBarButtonItem alloc ] initWithTitle: @" Pin" style: UIBarButtonItemStyleDone target: self action: @selector (pin: )]
176
+ [[UIBarButtonItem alloc ] initWithTitle: @" Pin" style: UIBarButtonItemStylePlain target: self action: @selector (pin: )],
177
+ [[UIBarButtonItem alloc ] initWithTitle: @" Decoration" style: UIBarButtonItemStylePlain target: self action: @selector (decoration: )]
179
178
];
180
- [item.leftBarButtonItems enumerateObjectsUsingBlock: ^(UIBarButtonItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
181
- obj.style = UIBarButtonItemStyleDone;
182
- }];
183
- [item.rightBarButtonItems enumerateObjectsUsingBlock: ^(UIBarButtonItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
184
- obj.style = UIBarButtonItemStyleDone;
185
- }];
186
- item.prompt = @" Prompt" ;
179
+ item.prompt = @" Fake NavigationBar" ;
187
180
_navigationBar = UINavigationBar.new ;
188
181
_navigationBar.translucent = YES ;
189
182
_navigationBar.backgroundColor = UIColor.clearColor ;
@@ -226,15 +219,17 @@ - (BLCollectionViewTagLayout *)blCollectionViewLayout
226
219
}
227
220
- (IBAction )pin : (UIBarButtonItem *)sender
228
221
{
229
- self.blCollectionViewLayout .sectionHeadersPinToVisibleBounds = YES ;
230
- self.blCollectionViewLayout .sectionFootersPinToVisibleBounds = YES ;
231
- }
232
- - (IBAction )unPin : (UIBarButtonItem *)sender
233
- {
234
- self.blCollectionViewLayout .sectionHeadersPinToVisibleBounds = NO ;
235
- self.blCollectionViewLayout .sectionFootersPinToVisibleBounds = NO ;
222
+ self.blCollectionViewLayout .sectionHeadersPinToVisibleBounds =
223
+ !self.blCollectionViewLayout .sectionHeadersPinToVisibleBounds ;
224
+ self.blCollectionViewLayout .sectionFootersPinToVisibleBounds =
225
+ !self.blCollectionViewLayout .sectionFootersPinToVisibleBounds ;
226
+ if (self.blCollectionViewLayout .sectionHeadersPinToVisibleBounds ) {
227
+ sender.title = @" Pined" ;
228
+ }else {
229
+ sender.title = @" UnPined" ;
230
+ }
236
231
}
237
- - (IBAction )showDecoration : (UIBarButtonItem *)sender
232
+ - (IBAction )decoration : (UIBarButtonItem *)sender
238
233
{
239
234
self.blCollectionViewLayout .sectionDecorationVisiable =
240
235
!self.blCollectionViewLayout .sectionDecorationVisiable ;
@@ -310,15 +305,17 @@ - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
310
305
- (void )collectionView : (UICollectionView *)collectionView didSelectItemAtIndexPath : (NSIndexPath *)indexPath
311
306
{
312
307
[collectionView deselectItemAtIndexPath: indexPath animated: YES ];
313
- [collectionView performBatchUpdates: ^{
314
- if (self.dataSource [indexPath.section].count == 1 ) {
315
- [self .dataSource removeObjectAtIndex: indexPath.section];
316
- [collectionView deleteSections: [NSIndexSet indexSetWithIndex: indexPath.section]];
317
- }else {
318
- [self .dataSource[indexPath.section] removeObjectAtIndex: indexPath.item];
319
- [collectionView deleteItemsAtIndexPaths: @[indexPath]];
320
- }
321
- } completion: nil ];
308
+ [UIView animateWithDuration: 2 animations: ^{
309
+ [collectionView performBatchUpdates: ^{
310
+ if (self.dataSource [indexPath.section].count == 1 ) {
311
+ [self .dataSource removeObjectAtIndex: indexPath.section];
312
+ [collectionView deleteSections: [NSIndexSet indexSetWithIndex: indexPath.section]];
313
+ }else {
314
+ [self .dataSource[indexPath.section] removeObjectAtIndex: indexPath.item];
315
+ [collectionView deleteItemsAtIndexPaths: @[indexPath]];
316
+ }
317
+ } completion: nil ];
318
+ }];
322
319
}
323
320
#pragma mark -
324
321
- (CGFloat )collectionView : (UICollectionView *)collectionView layout : (BLCollectionViewTagLayout *)collectionViewLayout maximumHeightForSection : (NSInteger )section
0 commit comments