manuelescrig / MEVFloatingButton

An iOS drop-in UITableView, UICollectionView and UIScrollView superclass category for showing a customizable floating button on top of it.
MIT License
296 stars 39 forks source link

Not working in child view controller #5

Closed obia75 closed 8 years ago

obia75 commented 8 years ago

I'm having problems getting MEVFloatingButton to work, probably due to my view setup. I have a parent view controller that adds a childviewcontroller like so:

UIStoryboard storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; OverviewGridController mainView = [storyboard instantiateViewControllerWithIdentifier:@"OverviewGridController"];
[self addChildViewController:mainView]; [self.view addSubview:mainView.view]; [mainView didMoveToParentViewController:self];

The child view controller has a collectionview on which I want to place the floating button.

I have tried to add it from the parent like this:

UIStoryboard storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; OverviewGridController mainView = [storyboard instantiateViewControllerWithIdentifier:@"OverviewGridController"];
MEVFloatingButton *button = [[MEVFloatingButton alloc] init]; button.animationType = MEVFloatingButtonAnimationNone; button.displayMode = MEVFloatingButtonDisplayModeWhenScrolling; button.position = MEVFloatingButtonPositionBottomRight; button.image = [UIImage imageNamed:@"icon_aplus"]; button.imageColor = [UIColor colorWithRed:44/255.0f green:62/255.0f blue:80/255.0f alpha:1]; button.backgroundColor = [UIColor colorWithRed:65/255.0f green:131/255.0f blue:215/255.0f alpha:1]; button.outlineColor = [UIColor colorWithRed:44/255.0f green:62/255.0f blue:80/255.0f alpha:1]; button.outlineWidth = 3.0f; button.imagePadding = 20.0f; button.horizontalOffset = -30.0f; button.verticalOffset = -30.0f; button.rounded = YES; button.shadowColor = [UIColor lightGrayColor]; button.shadowOffset = CGSizeMake(3, 3); button.shadowOpacity = 0.6f; button.shadowRadius = 3.0f;

[mainView setFloatingButtonView:button]; [mainView setFloatingButtonDelegate:self];

[self addChildViewController:mainView]; [self.view addSubview:mainView.view]; [mainView didMoveToParentViewController:self];

Button is not added and delegate methods are not responding.

I have also tried to add it in the child in it's viewdidload. Button is not added BUT when setting button.displayMode = MEVFloatingButtonDisplayModeWhenScrolling (and only then) the floatingButtonDidDisappear delegate method is triggered when the view is loaded.

Would really appreciate if someone can point me in the right direction.

obia75 commented 8 years ago

Oh, and I would prefer to handle everything from the parent. Both added the button and receiving the delegate actions.

obia75 commented 8 years ago

Just to take out the complexity I rewrote the code to handle everything in the same view controller (no parent/child dependencies). I got the collection view and mevfloatingbuttondelegate all wired up in the same view controller but can not for my life get the button to show! Is it suppose to work on IOS9 with an UICollectionView?

The button is not showing BUT when clicking on an item in the collectionview then the floatingButtonDidDisappear is triggered. So something is working apparently..

manuelescrig commented 8 years ago

The control is suppose to work on iOS9 properly with UICollectionViews. I don't know what can be wrong. One thing I can suggest is to make sure that the button and the delegate are set to the collection view and not to the parent view.

[self.collectionView setFloatingButtonView:button];
[self.collectionView setFloatingButtonDelegate:self]
obia75 commented 8 years ago

It is very strange indeed. Could it be that I have the collection view as a subview of a UIViewController. Must the main view controller by of the type UICollectioViewController?

manuelescrig commented 8 years ago

Should work in both cases.

obia75 commented 8 years ago

Hi again, I created a small project with the same kind of setup for you to test. Please have a look.

floatingButtonTest.zip

manuelescrig commented 8 years ago

Hi, I've been doing some debugging and I found out that in the case that the view (collectionView or tableView) was being layout before adding the button, in that case the button was not showing up. I fixed and released a new version 1.3. Now should work. Thanks for your help!

obia75 commented 8 years ago

Tested and confirmed working, thank YOU!