I had created a floating button so that it can be always shown to the user on the top, but when ever I present a controller using the UINavigationController
initiated, it hide behinds the presented view
I have a solution but it has to be implemented on every presented view controller.
I created a function by which I'm moving it to front, but for this I need to add code on every presented view controller. Is there any solution to do it a better way?
@objcMembers
final class MenuFloatingButton: UIView
{
static let tagValue = 99988
init(exitGuideTourButtonY: CGFloat)
{
let calculatedFrame = CGRect(x: ExitTourButtonConstant.leftPadding, y: exitGuideTourButtonY, width: ExitTourButtonConstant.buttonWidth, height: ExitTourButtonConstant.buttonHeight)
super.init(frame: calculatedFrame)
frame = calculatedFrame
layer.cornerRadius = ExitTourButtonConstant.buttonHeight * ExitTourButtonConstant.halfValue
clipsToBounds = true
tag = ExitGuideTourFloatingButton.tagValue
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapDetected))
addGestureRecognizer(tapGesture)
backgroundColor = ExitTourButtonConstant.buttonColor
let titleLabel = UILabel(frame: bounds)
titleLabel.text = ExitTourButtonConstant.buttonTitle
titleLabel.textAlignment = .center
titleLabel.font = ExitTourButtonConstant.buttonTitleFont
titleLabel.backgroundColor = .clear
titleLabel.textColor = .white
addSubview(titleLabel)
}
required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
theUnexpectedHasHappened()
}
}
and I'm calling it like this
- (void)addExitGuideTourDemoButtonView:(CGFloat)exitGuideTourButtonY
{
UIView* exitDemoButtonView = [self getExitButtonView];
if (exitDemoButtonView == nil)
{
exitDemoButtonView = [[ExitGuideTourFloatingButton alloc] initWithExitGuideTourButtonY:exitGuideTourButtonY];
[self.window addSubview:exitDemoButtonView];
}
else
{
// Do nothing
}
}
- (UIView*)getExitButtonView
{
UIView* exitGuideTourDemoButtonView = [self.window viewWithTag:ExitGuideTourFloatingButton.tagValue];
return exitGuideTourDemoButtonView;
}