UIScrollView embedded inside of a View that is paged using UIPageViewController - iphone

I have an app with the following layout:
UIPageViewController (set to scroll style)
--- UIViewControllers
--------UIView
-----------UIScrollView
---------------UIImageViews
Right now, the UIPageViewControllers work correctly and I can swipe left and right through the various viewcontrollers. However, on each view of the viewcontroller is a UIScrollView of UIImageViews. I cannot get this innerscrollview to respond to any swipes. I'm assuming the UIPageViewController is swallowing all the gestures.
I searched on SO and found some other solutions, namely to try to grab the delegates for the UIpageViewController's gesture recognizers, but since my UIPageViewController is set to Scroll style, self.pageViewController.gestureRecognizers returns 0.
Here is an image to show what I'm talking about:
Is there any way to fix this? Thank you!

Related

UICollectionView delegate is not responding when the UICollectionView is embedded within a UIScrollView

I have a UIViewController with a UIScrollView. The top half of the screen contains some labels and text fields. The lower half of the screen is the UICollectionView. The UICollectionView is embedded within the scrollview so that when the user scrolls down they are not limited to a half screen size collection view.
The collection view is presenting properly and the delegate is set as I've done countless times before.
I've purposely tested different solutions and if the collection view is added 'directly' to the UIViewController the didSelectItemAtIndex delegate method is called. When the collection view is added to a scrollView within the ViewController I get no response from the delegate method.
I have checked the Debug View Heirarchy and the ScrollView content size is sufficient to house the entire collectionView. The Debug view also shows the correct view as the UICollectionViewDelegate.
Any help would be appreciated.
Having written the question I worked out my issue.
As part of the layout within the first half of the screen, I have a UITapGestureRecognizer added to the UIScrollView to endEditing() should the user click outside of a UITextField. This tap gesture was receiving the tap and 'ending it' before it was passed to the UICollectionView.

How can I start showing a paging-enabled UIScrollView in the middle view?

I have a simple problem but I can't figure it out. I have a UIScrollView with three nested UIWebViews. I need to be able to "recycle" these views to actually scroll through lots of content.
My main problem is that I can't figure out how to show a view that isn't the very first, meaning that you can immediately swipe back from. Right now I have three views paging, but it starts at the first one, and you can move right two.
What can I do to make it so that I am always in the middle? With the ability to always swipe right OR left?
Thanks!
In the viewDidLoad or viewWillAppear methods for your viewController, try adding the following bit of code:
[self.myMainScrollView setContentOffset:CGPointMake(0,self.view.frame.size.width) animated:NO];
That'll scroll your larger scrollview over, so that the middle UIWebView is visible.
If that doesn't help, dig around in the UIScrollView and UIScrollViewDelegate documentation - you should find some good stuff there.

UIScrollView issue

I have a UIScrollView with textviews as subviews. Now in my app there are multiple UIScrollViews like these. And depending on the selection I display the appropriate UIScrollView on top of the previous view. This works fine in all cases except when the previous view has been a UIScrollView as well. In this case the behavior I get is of two UIScrollViews stacked on top of each other and both the views capture the scrolling events. The textViews from previous scrollView is also visible (not editable though) and overlaps and causes all sorts of issues. The thing is a full screen UIScrollView placed as subview to a previous view causes problems when the previous view is a full screen UIScrollView as well.
Any pointers on how to overcome this would be great. Is there anyway to notify the parent scrollview of the child's scroll events and move it the exact same way so this mess is masked?
Thanks!
UIScrollView documentation says:
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
As far as I know, it is generally not recommended to embed a UIScrollView subclass instance in a UIScrollView. In one of my projects, which is an IM application, I have a UIScrollView that contains many UITableViews, it works when you try enough but it really takes a lot of effort to handle subtle bugs and make it work properly.
It is really hard to say something useful for your problem without diving in to code, but i can recommend you to not add UIScrollViews one on to another like a stack. I'd try doing it by allowing only one UIScrollView at top, and removing others. When you need to show another one, remove the top one from view hierarchy and add the new one. I wish this helps, good luck.
Found a crude solution by presenting an empty view before I present the next scrollView. Added the scrollView as subview to this empty view (with a BG image) and added the to-be presented scrollView as a subview to it and then presenting this on top of the previous scrollView.

UITableViewController with a UIPickerView sliding up the screen

I have a UITableView where a cell needs to be filled in with a date by selecting it through a pickerview. Instead of pushing the pickerview onto the navigationController I would want to let it slide up halfway into the screen with the tableview still visible in the upper half of the screen. I've seen some apps doing this neat effect before but I don't see on how to accomplish this.
Anyone some helpful hints on this ?
I did this a little while back and asked about it.
I ended up doing exactly what the highest voted answer says: Put the UIPickerView in the same View as your other items and animate the sliding motion using UIView's beginanimation method.
Add a done button in your tool bar. Add a new target/action to the button to call a method on the UIViewController that has your table view and picker controller. Then have it animate the view back off the screen using a UIView animation block.

iPhone SDK view scrolling not rubber banding or using momentum from swipes

I'm having a fundamental problem with getting scrolling to work normally on my iPhone app. I have two views, each created in IB (although I've tried this programmatically and it makes no difference) which scroll very sloppily. Instead of the scrolling that we're used to (which is smooth and continues to scroll and eventually dampen and rubber band at the top/bottom), my scrolling only scrolls as long as my finger is in contact with the view. Swiping down quickly on a view has no more effect than swiping slowly. And when you scroll beyond the top or bottom, the view just stays there scrolled with empty area above/below.
One of my views is a UITableView and the other is a UIScrollView. Both have exactly the same problem and are in different XIBs, coupled to different classes, so this is why I think I'm missing a key concept in general.
My UITableView is a child to a UIView (since there is also a nav bar at the top) with my UIViewController's view connected to the UIView. The referencing outlets datasource and delegate are both hooked to the UITableView. Nothing is subclassed here aside from the ViewController of course which has overrides to populate the table.
In the second instance, I again have a non-subclassed UIView which my UIViewController's view is connected to. I have a subclassed UIScrollView as a child to the UIView and then a have a subclassed UIView (with larger size than the scroll view) as a child to the subclassed UIScrollView. This in itself seems ridiculously complicated to me, but I was not able to get scrolling working at all with fewer than 3 views (again there is a nav bar at the top of the non-subclassed UI-View). I am overriding drawRect: in my UIScrollView, which is putting the content up fine except for this scrolling issue.
Is there something I'm doing wrong organizationally? I've come across many suggestions on stackoverflow and other sites for UIScrollView and none make a difference. And I don't see anyone having scrolling issues with UITableView. I'm not pasting in any code because I would have to post full classes at this point (making the post ridiculously long) and I believe the problems to really lie with the way I'm using IB.
Thanks!!
OK, it turns out that this has nothing to do with UIKit. This code is part of a game I'm developing using cocos2d and that framework is what is causing the problem. For those who are developing on cocos2d, you cannot use FastDirector and expect scrolling to work in UIViews. Just remove any code like [[Director sharedDirector] useFastDirector] and everything will be fine.
Some code might help narrow down your problem.
In the mean time, try creating a new project in Xcode using the 'Navigation-based Application' template and take a look at how the navigation controller is being created in MainWindow.xib. Take a look at how the UITableViewController subclass called 'RootViewController' is defined and how the corresponding xib is setup too. You'll notice there is no UIScrollView explicitly defined anywhere but you get scrolling functionality from the tableview controller 'for free'.
This should give you a pretty good starting point down the right path. I question the need for overriding drawRect: without seeing some code or fully understanding your goal.
Take a look at:
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html
http://developer.apple.com/iPhone/library/featuredarticles/ViewControllerPGforiPhoneOS/UsingNavigationControllers/UsingNavigationControllers.html