Child view controllers not scrolling - ios

I have created a UI which has two child view controllers which slide in as menus from each side of the screen when a button is pressed (think hamburger menu). I have a table view on one and a collection view on the other. Neither will scroll for me or accept touch events. The code below is used to add to the parent container.
sidePanel = sb.instantiateViewControllerWithIdentifier("sidePanel")
self.addChildViewController(sidePanel)
self.view.addSubview(sidePanel.view)
sidePanel.view.center.x += self.view.frame.size.width
sidePanel.view.frame.size.width = 250
sidePanel.view.updateConstraints()
sidePanel.view.layoutIfNeeded()
Any ideas why touch isn't working? I've checked all the obvious solutions (userInteractionEnabled etc.).

The issue is caused by moving the view. The sidePanel is not contained within the view so is not receiving touch events.

Related

iOS - load and switch between pages using UIPageContol

I would like to use UIPageControl to navigate between different view controllers. I have 2 view controllers and another main view controller contains the UIPageControl. The 2 view controllers to be navigated between have been added as children to the main view controller. When I currently start the application, I see a blank screen. I used pageControl.currentPage = 0 but I am unable to understand why I am unable to see the views.
Note that I do not want to use UIScrollView in my application.
Edit - I have followed this tutorial http://www.wannabegeek.com/?p=168
But it uses scroll view. I do not want to use scroll view since it is creating some issues with a UIWebView and a CorePlot which I use in the different view controllers.
I seek guidance as to how to modify this tutorial without using scroll view. Thanks!
Adding the other view controllers as children just associates the view controllers - it doesn't add the views they manage as subviews. So, when you add them as children you should also add the subviews and set the initial frames. You might also want to add swipe gestures to trigger view animations to animate the frames of the views (though there are several other options, like using a scroll view).
As part of the animation to move the views you manually update the page control (that won't happen automatically).
The loadScrollViewWithPage method is the key. Call this with parameter 0 and then 1 to load both of the pages and add the views as subviews. Just change self.scrollView to self.view.
I would add a (two really, but get 1 working first) swipe gesture to the page control. Then when it is swiped you can move the other views.
The swipe gesture callback:
- (void)swipeRightToLeftGesture:(UIGestureRecognizer *)gestureRecognizer
{
[UIView animateWithDuration:1
animations:^{
for (UIViewController *vc in self.childViewControllers) {
CGRect frame = vc.view.frame;
frame.origin.x -= self.view.frame.size.width;
vc.view.frame = frame;
}
}];
}
This iterations over the child view controllers and animates the frames of their views to move them to the left. The swipe left to right handler will be the same except it will += the width to move the to the right.
[Code Edited - syntax]
UIPageControl doesn't handle swiping or page switching for you. In order to use it, you NEED to have a scroll view (or some other kind of control) to handle the swipes and the actual page switching, and then implement the UIScrollViewDelegate protocol (or whatever protocol you need for the control you're using) to know when the page control should update it's current page position (the currently selected dot). UIPageControl itself doesn't really do a whole lot.
UIPageControl does not do anything much except display some dots. If you want a way of switching between view controllers it sounds like you want UIPageViewController, which is a completely different animal. A nice feature of UIPageViewController is that it can display a UIPageControl as a way of indicating / switching view controllers, which may be just the kind of thing you're after.

iOS6 - Changing embedded subview in a view

I'm looking for some ideas what's the best way to implement the following behaviour (and a starting point in code/pseudo-code if possible):
BookViewController with ViewA - contains some UILabels (e.g. information about a book)
MainViewController with ViewB - contains some UI elements and displays ViewA in the middle (one view at a time)
The user should be able to swipe inside ViewB to view different books i.e. I will need to manage a number of ViewA views, create new ones and populate them with new data, and then replace the current instance visible in ViewB. So effectively I'll be changing views in the centre of the screen. What's the easiest and most efficient way to accomplish this functionality? Any suggestions comments are appreciated - thank you.
You just need one view controller. It should control a scroll view with paging enabled at the center and e.g. three book views, one visible and the ones left and right of it. The controller should manage the data displayed in these book views.

ImageView not responding to touches

In XCode, I created a xib file with several image view, some stacked on others. The entire view has a single view controller that has a connection to every image view. I guess my first question is, are all the image views direct subviews of the entire view? Anyways, when ever the over all image view is touched, I detect it with touches began / touches moved. It works perfectly. However, there is one image view in particular that I want to know if it is being touched. How can I, from the master view's touches began / touches moved, find out if a sub view within it was touched? I want to do it this way because everything else I tried did not work. For the sub view, i created a view controller and set its view to the sub view in question. I set up the touches began / touches moved methods inside the controller, but they do not react to touches at all.
For UIImageView instances, you need to explicitly do setUserInterActionEnabled=YES

Use a UIView ( created using xib) multiple times as a subview to the same view

My requirement is that I want to create a view which has to be added to a scrollview multiple times ( 12 times for each month ) with a pagecontrol , loaded with different data.
The requirement specifically is to use a scrollview/pagecontroll with previous/next page visible.
I have successfully done that by manually creating the view, but when i reduce the alpha of the added view, the alpha of all the ui components added to it is reduced.
hence i need to create the view using xib.
But view instantiated using xib are getting added to the scrollview only once. remaining pages as just blank.
Any ideas on how to proceed here will be highly appreciated.
Go back to creating the view manually, but instead of adding ui controls to it, create another parent view and add your created view and the other ui view as children to this parent view,
Now when u decrease the alpha on the view, other ui controls will not be affected since they will not be children to this view.
So your new view arrangement would be:
Parent View -> your created view (the one that you want to change its alpha)
-> other ui controls
So your view will not be the parent of other ui controls
You will have to create different instances of same UIView class and add as subview on UIScrollView. And for alpha, the alpha set for parent view will override all its child.

How to edit floating view added to scene dock in storyboard?

I have a view controller on my storyboard set up with a tableview. I want to have another view as a floating view on top of the table view. So, I drag a view (actually a toolbar object) and drop it into the scene dock so that in code I can add it to the subviews and position it so that it floats. I have no questions about the coding; just laying out the view in storyboard.
How do I open the view object that I added to the scene dock so that I can add buttons to it, etc., and design it visually?
I know it's possible since I did it accidentally in another project. The toolbar was in the view controller's scene dock and displayed separately with it's own scene dock. It's very frustrating knowing it can be done, but not knowing how to do it!
(source: bikibird.com)
!
Okay, this is how I did it (also by accident).
I had created an (IBAction) and was trying to connect to a button. So I drug a line from my code to the button (in the list of items). For some reason it wouldn't connect so it seemed to hover over it for a few seconds.
All of a sudden the view (with the button) popped out and displayed next to my uiviewcontroller just like you described. I had done this also by accident, but this is the first time I managed to get it to work for me.
Let me know if this works for you as well!!!
I dont know how to show a view like in your picture, but to design a view visually i put it, for example, as head view on my TableView, design it and put it back to the dock.
It's only a workaround, but that helps me.
All I had to do was drag a UI object (in my case it was a UISlider) from the object explorer on the right into the view I wanted to pop out in the scene explorer on the left

Resources