Commits

José Manuel Sánchez Peñarroja  committed 57df5fc

Added method to remove view controller from parent. Improvements to collectionviewdatasource

  • Participants
  • Parent commits 17d3a94

Comments (0)

Files changed (7)

File Example/Example.xcworkspace/xcuserdata/josanchez.xcuserdatad/UserInterfaceState.xcuserstate

Binary file modified.

File bmf/ios/behaviors/BMFCollectionViewZoomSelectedCellBehavior.m

 	[containerView bringSubviewToFront:view];
 	view.frame = self.oldFrame;
 	
-	[UIView animateWithDuration:0.5 animations:^{
+	[UIView animateWithDuration:0.2 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:1 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
 		view.frame = [BMFUtils rectToFitRect:view.frame toRect:containerView.bounds mode:BMFContentModeScaleAspectFit];
-	}];
+	} completion:^(BOOL finished) {
+		
+	}];	
 }
 
 - (void) stopZooming:(UIView *) view containerView:(UIView *) containerView {

File bmf/ios/behaviors/BMFUpdateCollectionViewBehavior.h

 
 - (instancetype) initWithView:(UICollectionView *) collectionView;
 
-
 @end

File bmf/ios/behaviors/BMFUpdateCollectionViewBehavior.m

 }
 
 - (void) viewWillAppear:(BOOL)animated {
-	[self.collectionView.collectionViewLayout invalidateLayout];
+	// Update layout without animation
+	[self updateLayoutAnimated:NO];
+}
+
+- (void) viewDidLayoutSubviews {
+	[self updateLayoutAnimated:NO];
 }
 
 - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
-	[self.collectionView.collectionViewLayout invalidateLayout];
+	[self updateLayoutAnimated:YES];
+}
+
+- (void) updateLayoutAnimated:(BOOL) animated {
+	if (animated) [self.collectionView performBatchUpdates:^{} completion:nil];
+	else [self.collectionView.collectionViewLayout invalidateLayout];
 }
 
 @end

File bmf/ios/categories/UIViewController+BMF.h

 @property (nonatomic, strong) BMFPopoverController *BMF_popoverController;
 
 - (void) BMF_addChild:(UIViewController *) detailVC addSubviewBlock:(BMFActionBlock) block;
+- (void) BMF_removeFromParent;
 - (void) BMF_popToRootViewController;
 
 

File bmf/ios/categories/UIViewController+BMF.m

 	[detailVC didMoveToParentViewController:self];
 }
 
+- (void) BMF_removeFromParent {
+	[self willMoveToParentViewController:nil];
+	[self.view removeFromSuperview];
+	[self removeFromParentViewController];
+}
+
 - (BMFPopoverController *) BMF_popoverController {
 	return objc_getAssociatedObject(self, @selector(BMF_popoverController));
 }

File bmf/ios/data/data sources/BMFCollectionViewDataSource.m

 	[_collectionView reloadData];
 }
 
+- (void) setCellRegister:(id<BMFCellRegisterProtocol>)cellRegister {
+	_cellRegister = cellRegister;
+	[self registerCells];
+}
+
+- (void) setSupplementaryViewRegister:(id<BMFViewRegisterProtocol>)supplementaryViewRegister {
+	_supplementaryViewRegister = supplementaryViewRegister;
+	[self registerViews];
+}
+
 - (void) registerCells {
-	if (self.cellRegister) [self.cellRegister registerCells:self.collectionView];
+	if (self.collectionView) [self.cellRegister registerCells:self.collectionView];
 }
 
 - (void) registerViews {
- 	if (self.supplementaryViewRegister) [self.supplementaryViewRegister registerViews:self.collectionView];
+ 	if (self.collectionView) {
+		[self.supplementaryViewRegister registerViews:self.collectionView];
+	}
 }
 
 #pragma mark Observe data changes
 	return [self.dataStore numberOfSections];
 }
 
-
 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
 	return [self.dataStore numberOfRowsInSection:section];
 }
 	
 	if (!configurator) {
 		DDLogError(@"Error: No configurator found for cell: %@ and item: %@. Did you forget to create or register it?",cell,item);
+		return nil;
 	}
 	
 	[configurator configure:cell kind:BMFViewKindCell withItem:item inView:collectionView atIndexPath:indexPath controller:self.controller];
 
 	Class<BMFViewConfiguratorProtocol> configurator = [BMFViewConfigurator configuratorForView:view kind:kind item:item inView:collectionView];
 
+	if (!configurator) DDLogWarn(@"Warning: no configurator found for supplementary view");
+	
 	[configurator configure:view kind:kind withItem:item inView:collectionView atIndexPath:indexPath controller:self.controller];
 
 	return view;