Hello,
Thanks for this library, it's awesome!
I found an issue that if the app has multiple windows and subviews, the FPPopover is not being displayed on the visible view.
Checking the code I found that -(void)presentPopoverFromPoint:(CGPoint)fromPoint; on FPPopoverController.m is doing the following:
...
NSArray *windows = [UIApplication sharedApplication].windows;
if (windows.count > 0) {
_parentView = nil;
_window = [windows objectAtIndex:0];
// keep the first subview.
if (_window.subviews.count > 0) {
_parentView = [_window.subviews objectAtIndex:0];
[_parentView addSubview:self.view];
[_viewController viewDidAppear:YES];
}
}
...
So, while retrieving the windows and subviews arrays, it is not checking if there are multiple elements, it only took the object at position 0:
_window = [windows objectAtIndex:0];
and
_parentView = [_window.subviews objectAtIndex:0];
That would fail to load the FPPopover on the visible view because as Apple documentation says:
@Property(nonatomic, readonly) NSArray *windows
Description
The application's visible and hidden windows. (read-only)
This property returns an array of the application's visible and hidden windows. The windows are ordered back to front.
and
@Property(nonatomic, readonly, copy) NSArray *subviews
Description
The receiver’s immediate subviews. (read-only)
You can use this property to retrieve the subviews associated with your custom view hierarchies. The order of the subviews in the array reflects their visible order on the screen, with the view at index 0 being the back-most view.
So, the windows array will not fail because the position 0 is the visible window, but in the case of the subviews array it is going to fail, or at least is not going to show anything to the user, because it is using the back-most subview, which is not currently being displayed. That would be fixed using the following code:
...
NSArray *windows = [UIApplication sharedApplication].windows;
if (windows.count > 0) {
_parentView = nil;
_window = [windows objectAtIndex:0];
// keep the first subview.
if (_window.subviews.count > 0) {
_parentView = [_window.subviews objectAtIndex:(_window.subviews.count - 1)];
[_parentView addSubview:self.view];
[_viewController viewDidAppear:YES];
}
}
...
which the important code line is:
_parentView = [_window.subviews objectAtIndex:(_window.subviews.count - 1)];
That would retrieve the front-most subview and display correctly the FPPopover on the visible view.