UIScrollview with paging and interaction - iphone

I am trying to wrap my head around how this would work. I want to create a horizontal scrollview consisting of "tiles" that are added and that you can scroll through (paging). On each tile will be a main image and other various smaller images that will act as buttons and launch popovers and such. I understand that I can create my "tile" as a uiview subclass programmatically or in a viewcontroller which then can have it's view added to the main uiscrollview. My question is where do I detect touch events of the small button-like elements in each tile? Would the main viewcontroller that manages the scrollview be the one that would handle the touches of the subviews' subviews?

You would detect the touch events for your tiles in whatever view handler you have them in. Basically you would have one view with a scroll view on it, then you would create another view that would have your tiles, within the view that contains your tiles is where you would handle the touch events for them, but you will have to keep track of which "Page" you are on to know what actions should be performed.
This is the best example I have found on using the page controls.

Related

Difficulty handling touch events with a UITableView

I am implementing a Google+ type iPhone application. The UI consists of a number of screen-sized panels, and the user can move through these panels horizontally by swiping left or right. I am not using a UIScrollView for this, but am instead implementing it as a series of UIViews on top of a master UIView - I override the touches... events for the UIViews and pass them on to the master UIView to handle repositioning the panels.
My code works perfectly as long as each panel is just an empty UIView (or if it only contains controls that don't pick up touch events, like a UILabel). The problem I'm facing is when I try to put a UITableView on one of the panels. Because the UITableView picks up the touch events, this is interfering with my own code that uses the touch events to slide the panels horizontally.
I have tried two approaches, neither of which is working perfectly:
First approach: I subclass UITableView, overriding the touch... events (touchesBegan, touchesMoved, and touchesEnded). In the overrides, I pass the events on to self.nextResponder and then to super. On my table, I also set canCancelContentTouches = NO;. This works somewhat - if I start swiping with a perfectly horizontal movement, the underlying panel containing the table view moves left and right. However, if I begin the process by swiping vertically, the table view begins scrolling up and down and no horizontal movement happens at all until I lift my finger. Also, if I begin swiping horizontally the left-right movement of the panel happens, but until I life my finger no vertical scrolling of the table view is possible (I'm trying to get a solution where vertical movement scrolls the table view and horizontal movement moves the underlying panel left-right). BTW, without the canCancelContentTouches = NO; call, the touch events stop coming altogether as soon as the table view is scrolled even a little bit.
Second approach: I subclass a UIView, set it's background color to transparent, and then place it over top of the view containing the UITableView. In this overlay subclass, I override the touch events and 1) pass them on to the underlying UITableView and then 2) pass the touch events on to the underlying UIView that handles the left-right swiping. With the approach, the left-right panel movement works perfectly. With the table view, unfortunately, the passed-through touch events allow me to click the table view and change the selected row (so I know the events are at least partially going through), but I can't scroll the table view up or down.
Any suggestions for how to do this correctly are welcome.

how to drag an uiimage from scrollview to another uiimageview in iphone sdk

In My Application,i am having one scrollVIew containing multiple images.
and out of the scrollview i have one uiimageview.
i want to Drag any image from ScrollView and drop it on uiimageview which is out of the scrollview.
is it possible?
help And suggestions are appreciated
Thanks in advance.
gamozzii's reply is close to what you need to do, but there's one problem. An UIScrollView will eat touches, so tapping on an image will have no effect.
As a result you will have to subclass the UIScrollView
I have written a small functional app to illustrate dragging the image from a scroll view into an image view. You can download the project here.
Yes this should be possible, you will need to implement the touch/drag events directly.
Check out the touchesBegan, touchesMoved etc. delegate methods in UIResponder.
One approach would be to subclass imageview and implement touchesBegan, touchesMoved in it, and use this imageview subclass to display your images in the scroll view.
On the touchesBegan create a new image view and add it to the outer view and set its image to be the same as the one in the scroll view. You need to overlay it directly over your source image in the scroll view so adjust its frame origin to be relative to the outer view you will need to use the scrollview origin and also the content view size and offset of the source image view inside the content view in order to recalculate the new origin in the outer view.
Then on the touches moved, simply readjust the frame of this image in accordance with the coordinates from the touches moved so that the image follows the touch.
Do a boundary check against the frame of your target imageview - once the user drags it into this boundary, make that target imageviews image the same as the image in the view being dragged and remove the dragged image from the containing view and release it.
In case you're still interested in another solution (and for other users of course):
I did implement that behaviour before just like gamozzii recommended.
I set canCancelContentTouches = NO on the UIScrollView to make sure the subviews handle there touches on their own. If a subview (in your case an image) was touched, i moved the view out of the scrollview onto the superview and started tracking it's dragging. (You have to calculate the correct coordinates within the new superview, so it stays in place). After dragging finishes, i checked if the target area was reached, otherwise I moved it back into the scrollview.
The subviews are handling the dragging on there own via (touchesBegan:/Moved:/Ended:/Cancelled:).
If that's not detailed enough, here's my example code: Github: JDDroppableView

Nested UITapGestureRecognizers

If I have several views stacked one on top of the other (all subviews of each other) where each one has a UITapGestureRecognizer attached to it.
How can I make sure that the highest visible view received the gesture and not the furthest ancestor?
The tap gesture is only valid for the current view. Further the frame of your current view(-controller). You can create a blank view over the hole screen and put in there your current view lets say 200x200 px. (essentially it is both in the same view)
Now all gestures should respond to your topmost view-controller. The bad thing about that: you can't access the views below anymore.

Can I make a UIScrollView only scroll when i interact only with specific places in the view? UIScrollView iPad

I have a UIScrollView wich contains 2 views the first at offset 0 and the other at offset 800.
I want the user to be able to scroll down but not always, because in the upper view i have another controls tha receive touch input and dragging and sometimes when you are dragging if your touch is just a little bit out of the control the scrollview scrolls and that's very annoying. So i want that the scrollview only scroll in certain zones.
What you basically need is to subclass the UIView that should intercept touches outside it's frame and override it's hit test method.

Scroll view touch detection

I have a problem in the touchesMoved handler with a view that is added onto a UIScrollView. I add a number of labels to the scroll view. Each of these labels contain some text and, on swiping my finger on the labels, I have to play a specific file for that text.
If I just add the view onto the window directly, I get all of the touch events in touchesMoved without any problem. When I add my view onto the UIScrollView and then add this to the window, there is some lag in the touchesMoved handler. I am not getting continuous touch points in touchesMoved as with the normal view. As a result, while swiping the finger from the view, it happens that some labels are missed.
Is the problem due to scroll view? The same code runs perfectly in normal conditions (without a scroll view).
Does anyone have any solution to this?
UIScrollView sets a timer on touchDown to be able to know if it should handle scrolling or if it should pass the events on to subviews.
There is a property on UIScrollView for controlling this behaviour:
#property(nonatomic) BOOL delaysContentTouches