Scrollview and image dragging issue - iphone

I have a scrollview that has a number of custom imageviews in it. I use the custom imageviews as I need to be able to drag any one of them off the scrollview and to another location on the iPad screen, bit like a photo picker.
Problem is if I want to scroll the scroll view most of the time the custom imageview gets the touch and moves rather than the desired scroll?
I notice in the sample code from Apple using the autoscroll example that they have the same issue but they have left a large gap between the images....ugly!
Is there a way to let the app know when you want the touch to be a scroll and when to be a drag?
Thanks

You could make a drag require holding for 1 second, similar to the behavior of the home screen when in editing mode: if you want to scroll, you just flick; if you want to drag, hold down for a moment until the icon enlarges, then you can move it.

Related

Adding UIButton to UIImageView within UIScrollView on Swift

I am writing an application for an event my organization is hosting using Swift. I have an image with the floor layout and want to add buttons to select locations (such as bathrooms, entrances, exits, emergency sections, etc) so that people can click them and information about the location pops up.
I currently have an imageview with the floor layout within a scrollview to allow the user to zoom in and out of the image. When I try to add buttons to the scrollview they don't stay relative to the image when zooming in and out, nor do their size change. I have tried adding constraints on to make the location stay the same when zooming in and out.
It also won't let me relocate the button on the storyboard to be a subview of the imageview. Looking up similar solutions says to add the button programmatically as a subview of the imageview but then it'd be really hard to put the 100+ buttons in the right location. Any suggestions as to how to go about this?
you have no other choice instead of adding by code.. because from code you can add as subview of image view , whereas Storyboard wont add buttons as subviews of imageView, but it will add buttons as subview of Scroll View

UIScrollView with UIButton doesn't scroll when touch down on button

I've got a UIScrollView in my UIView. I've added some UIButtons to the scroll view.
If I touch down not on a button and drag, the scroll view drags fine.
If I touch down on a button and drag then the scroll view doesn't move.
I want the scroll view to always scroll around if dragged and the buttons only get selected on the Touch Up Inside event.
I don't want to check "Delay Content Touches" because I don't want to have to wait for the delay.
Does anyone know what I need to do to get this to work?
Regards,
Rich
Perhaps just outdated, but Redent84's answer is plain wrong.
You can solve this by adding:
scrollView.canCancelContentTouches = YES;
There's no automatic way of doing that. You have to manually handle the touch event, and then determine what the user wants to do, if he moves the finger X pixels up or down, then he wants to scroll, and if he releases the touch inside the button, then he probably wants to activate that action.
Regards!

In iphone, how to select desired size image from an image

Like in MS paint when we want to select portion of image we select rectangular box & drag over the image by click & holding left mouse key till the desired location.
How can we do the same functionality in iphone.
Plz help....
You can use multitouch in an image view and touch two points to mark the corners of the selection rectangle. You can then drag both fingers around to change the selection rectangle, and lock the selection when you lift one or both fingers.
Another alternative is to put the image in a scrollview. Then zoom and pan the subview around inside the scrollview until the portion that just fits the full scrollview represents the selection. You can put the control buttons outside the scrollview, or have them fade out and fade back in after some amount of time after the user has stopped moving the selection around.

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.

iPhone SDK: disabling cllipping for UIScrollView

I'm working on an iPhone game, and trying to use a UIScrollView to display some icons, which I then want to enable the user to drag off the bar being scrolled, onto another view (basically, dragging them from their hand into play on the game board). The problem is that the UIScrollView clips everything outside it's own bounds.
Here is a picture of what I'm trying to do:
Functionally, it actually works, in that you can drag the icons up to the white board fine...but you can't see them as you are dragging...which is not acceptable.
Does anyone know if you can temporarily disable the clipping that a scroll view does, or is there some way to get around it? Hacky or not, I would really like to make it happen.
Does anyone have any other possible solutions for this? Or maybe any alternate approaches? I've considered if maybe a page view might work, but haven't tried it yet...and it's not at all as good of a solution as the scroll view.
Worst case I can just go back to not having the bar scrollable, but that really puts a damper on some of my game mechanics, and I'm really not too excited about that.
I think you're looking for the clipsToBounds property of UIView. I've used it successfully with UIScrollView:
scrollView.clipsToBounds = NO;
However, the dragging you want to do from the scroll view to the game view may require you to remove the icon view from the scroll view, place it in the superview at a position corresponding to its visible position within the scroll view (calculated using the scroll view's origin and content offset), and have that track the user's finger movements. On a release of the touch, either drop it on the game view at the proper position or return it to the scroll view.
I'm not 100% sure I understand the question but I think you should look into the z order of the scrollview and the whiteboard. It may be that the drag is just going behind the whiteboard.
Failing that, it would be useful to see all the bounds of your view heirarchy.
I also think a better solution allround might be to create a "sprite" to animate underneath the players finger - you could offset the drawpoint of the sprite from the touchlocation so that the player can see what they are dragging.