Touches lost on UIScrollview - ios

I am using a UIView subclass which can be resized by dragging on the borders and it is added as subview on a UIScrollView. I am also using a UIGestureRecognizer subclass to move the view on the UIScrollView such that the custom view remains visible and the scrollview autoscrolls.
This setup is working as intended but for one problem. Whenever the custom view is resized, the touches on UIScrollView are lost, i.e the scrollview does not recognise the tap or scroll on it unless the custom view is tapped or dragged once again. I have found that after resizing, neither custom UIView nor custom UIGestureRecognizer's touches began, cancelled or ended are called.
Where might the problem be?

Related

Zooming on content view inside of scrollview doesn't work

I'm creating a scrollview with content view inside of it. inside of the content view there are buttons.
from this point, i already can zoom and pan on content view. but when the touch happen on a button the scrollview doesn't zoom.
I have just had the same problem and solved it with the following steps :
Create a UIView.
Create a UITapGestureRecognizer
Add the UITapGestureRecognizer to the UIView to handle taps.
Create a UIButton.
Disable User Interaction (isUserInteractionEnabled = false) on the button.
Add the UIButton as a SubView of the UIView.
In the UITapGestureRecognizer tapped selector, handle the UIButton touchesUpInside call.
Add the first UIView into the UIScrollView.
Make sure the UIScrollView delay content touches delaysContentTouches = true
The UIScrollView should be able to now seamlessly zoom and you can respond to your buttons.
You can skip the button altogether if you want and just handle the Tap in the Gesture Recognizer. I had to do it the way above because the buttons were a custom sub classed buttons and had a lot of additional custom rendering and functionality included.

Scroll View doesn't scroll when touching and holding then swiping

I have UIScrollView with other UIView elements inside. My other UIView elements are mostly segmented controls. If I click on a UISegmentedControl and hold for a second and then try to scroll, then no scrolling happens. I can only scroll when my finger touches and swipes immediately. I checked other iOS applications such as mail. The behavior was that you touch and hold on a mail, then it's highlighted, but as soon as finger moves away, the scrolling happens and highlighting is undone. How can I implement this behavior?
The issue was the property of UIScrollView. The property canCancelContentTouches was set to NO. Because of that, touch events were handled by subviews of scroll view and swiping didn't cause scrolling.
You can follow one of these steps:
If you are using UISegmentedControl over you UIScrollView, instead of that, add the UISegmentedControl over your controller's view.
If you want to use UISegmentedControl over your scrollView, then you have to create a custom scrollView by creating a subclass of UIScrollView and use an image view instead of UISegmentedControl adding the labels which can act as the segments. This is because your UISegmentControl itself is a touch handler and it breaks the UIResponder chain. So, the scrolling might face issues during the touch events.
Please let me know if any of these works. Thanks :)

Weird behavior when subclassing UIScrollView

I have a scroll view that has a variable number of UIImageView subviews. I subclassed UIScrollView because I want to be able to move and resize the images with gestures, and do some other custom behavior. As soon as I switch the scroll view to my subclass in the nib file, some strange things happen: the scroll view will expand vertically and cover other views when scrolled upward, and the bottom edge stops short of the full screen and leaves a big gap...but when I change it back to a regular UIScrollView, it's fine. I don't override anything in my subclass or set anything in the nib that I believe could cause this...all I do is override the addSubview method, and add gesture recognizers to subviews as they are added to my scroll view, and of course have methods to handle those gesture recognizers. Any ideas as to what I'm doing wrong?
Thanks in advance!
Got it! The problem, it seems, was that I had a method called handlePan...by doing this I had inadvertently overridden an identically-named method of UIScrollView. So, my handlePan (which I had intended only to handle the pans for my subviews) was instead handling all pans, including the scrollview's built-in one, and causing the weird scrolling. Whoops! Problem solved.

Drawing in screen with finger in UITableView

I am following this excellent small tutorial about drawing on screen in the layer of a UIView (subclass).
http://spritebandits.wordpress.com/
It just works.
There is just one thing. I placed this view as subview of a UITableViewCell which, naturally, is displayed as part of a UITableView.
I guess I would have the same issue when I would place it within an UIScrollView. (UITableView inherits from UIScrollView anyway)
Touches are triggered by my painting view as long as their related movement is horizontal. As soon as I move the finger kinda vertical, even partly, then the UITableView takes over and scrolls the table.
Is there any proper way of stopping the Table to taike control of the touches while the touch is actually within my view?
If it is of importance: I am using storyboard. The cell is a prototype cell with its own subclass of UITableViewCell.
I've implemented this using the same class "Canvas" you're saying and also inside a UITableViewCell. But I didn't use the entire cell for drawing, only a UIView inside of the UITableView as a subview.
I reached the whole user experience by activating and deactivating the UITableView scrolling when that UIView (subview of the cell where I allow the drawing) fires touchesBegan or touchesEnded. So when they touch/move inside the UIView, they're drawing. When it's outside, they're scrolling. So they can't scroll on the UIView because they will be drawing.
The problem in your case is that since the whole cell is the view for drawing, the user cannot scroll in this concrete cell because it's the drawing one.
Hope this will help.
I dont have an answer for that. But there is essentially a work around.
You could get the user in to a drawing mode, where the scrolling for a UItableviewcell is disabled and then
once the user is done with drawing, you could enable scrolling again.
Inclusion of a button anywhere on the screen would help you switch modes.

How do you receive touches in views added to a subview

I have been adding several subviews ("touch subviews") to a scroll view which respond to touches. The touch delegate methods in each of these subviews all fire nicely.
I have one subview (bodyClock) which holds the main content of the scroll view and is the viewForZoomingInScrollView. In order for the "touch" subviews to zoom properly I find now that I have to add them the bodyClock subview instead of the scroll view. When I do this, however, the "touch subviews" no longer respond to touches.
I have tried all sort of things with first responder without any success. Any help pointing me in the right direction would be appreciated.
OK, I found my problem I had a subview acting as a time mask in the scroll view that I think was responding to touches. This became evident when I noticed that the touch subViews did not respond to touches while the mask was over them. Because the mask was a subview to the scroll view, it would move when zooming such that a touch subview in the bodyClock view would come out from underneath the mask and suddenly start working.
Moving the mask from the scroll view to the bodyClock subView along with the "touch subviews" fixed my problem. Now all the subviews scroll and zoom properly, and respond to touches.

Resources