iOS - UIButton on UIPageControl not working - ios

I am using UIPageControl as indicator between different page (view controllers) of my application. In each of the view controllers, I need to have a different button on the left corner on the UIPageControl. If I place a UIButton at that position on each of the view controllers, I see it on the UIPageControl but the buttons do not respond to the touch event. Is there something I am missing? Or is there an alternative to do this? Thanks.

I guess the page control and the view controller view are both subviews of the same view. In this case, the button is drawn outside of the view controllers view bounds. This is allowed by default, but it does have the side effect that the button can't be tapped on as the superview doesn't handle the touch.
You should have the buttons on the page control owned by the 'super' view controller (the controller that owns the root view containing the page control and the child view controllers). Then, when a button is tapped it should tell the child view controller about it so that it can take the appropriate action.

Related

How to make UIButton stay always on top of loaded child view controllers?

This is how I have my controller setup:
The UIView is a container view. Inside this I load another view controller.
This is how the stack of controllers look:
Safe Area
ScrollView
ContainerView
Close Button
After I do this my close button at the bottom will be under the new loaded controller so I cannot interact with it.
Is there a way to always make the close button stay on top of the loaded view controllers ?
You can try this
self.view.insertSubview(child.view, belowSubview: closeButton)

IOS: Disable scroll of a superview in IOS

All I am working on a legacy code that does the following
creates a child view controller and add's it to the parent controller
The child view controller is presented in the parent VC. So the animation starts from bottom towards the top, but only up to a specific location, leaving a height of 100 from the top.
So I have a superview being displayed within the bounds (0,0), to (SCREEN_WIDTH, 0) and (0, 100) and (SCREEN_WIDTH, 100)
The child view controller view is displayed below it.
If you tap on any part of the screen that is a part of the parent view, you can swipe and up down, causing it to scroll. I don't want that. How do I disable scrolling of the superview when the child view is loaded?
I have tried the following solutions.
Create a delegate protocol that parent VC implements to try to set the content off set to CGPointZero. This delegate is called from the child view.
Create a delegate protocol that parent VC implements and call the following function from the parent VC (which has a custom UIScrollView) that executes the following
self.view.scrollEnabled=NO;
This option did not work for me either. Is there any other way for me to do this?
Present a child view controllers view fully with clear color . Inside that view make a subview by doing like this " but only up to a specific location, leaving a height of 100 from the top." so nothing is touchable from the parent's view. Or do what ever your doing ,but when child is about to present disable parent controller view with user interaction enable to 'NO' or cover it with clear color view.When child is diss missed enable the parent controllers view or remove that cover view.

iOS: Slide in view created in storyboard

I don't know how to do this. I have a view created in Storyboard containing a picker wheel and slightly below a button.
Now if the user clicks a button in my view controller I want this "view container" slided in from the top and as soon as this button (within this view container) is clicked, the view should slide out to the top again. But how can I do this? As said I created this view container completely in my storyboard over my main view controller but don't know how to program this and also not what to do with the vertical constraints?
You want this view to be managed by a view controller. When the button is tapped, you call the view controller with a down animation. When the button under the picker wheel is tapped, you dismiss the view controller with a top animation.

Segue from a scrollview

I have a UIscrollview that takes up about half of a screen. The scrollview contains a series of view controllers that have buttons that have segues to another view controller. When that segue is followed, it loads the view controller on top of the current scrollview.
I want that new view controller to act like any other modal segue would act if the button was not within a subview or scrollview. In other words, take up the whole screen.
Can you use segues from within a subview or a scrollview?
Thanks!
The scrollview contains a series of view controllers that have buttons
that have segues to another view controller.
An instance of UIScrollView can't "contain" view controllers -- it can only contain other views. It might contain views that are managed by other view controllers, but if you're using many view controllers all at the same time you may want to read Am I abusing UIViewController Subclassing?.
I ended up just using delegates and protocols between the views in the scrollview and the parent view controller and then I launch the new view from the parent view controller. Seems to be doing the trick.

UIViewController as a subview for other view controllers

My app has a menu button which is available in every view controller. Every time a user taps on the menu button, a small menu pops up. The menu has multiple UIButtons, and each button links to another view controller.
My current solution is to create a view controller with a nib for the menu view and add it as a subview to each of the other main view controllers.
Is there is a better solution?
There could be multiple ways of doing it and I don't think there is the best answer.
However, in the performance perspective, implementing a view container such as UINavigationController or UITabBarController would be most effective.
Implement a root view controller (whose view is added as the only direct subview of the application window), and add the menu as a subview of its view. Let the root view controller decide (or know) which view to display, and add the view as a subview of its view, below the menu.
In this way, the view for the menu need not be removed and added again to the current view hierarchy.

Resources