I have been struggling with how to detect touches on a portion of a tall textview subview that extends below the visible view of a screen.
The view hierarchy looks like this:
View Controller
UIView (UV,visible portion of screen)
UIScrollView (SV)
UIView (CV,Content View--contains all elements)
UITextView (TV)
When the screen first loads, a portion of the textview (TV) is visible, the portion contained within the UV, or visible portion of the screen. When you scroll, you move the scrollview (SV) behind the visible portion of screen, revealing portions of the textview that are outside the original UIView (UV).
When you scroll down, while you can see the lower portions of the textview, they do not respond to touches.
Can anyone suggest a way to make an entire textview reponsive to touches even, portions of the textview that extend below the visible UIVIew?
Do I need to make UIVIew (visible portion of screen) bigger than the actual phone screen? Or what can I do.
Of note, the gesture recognizer is currently added to the view in viewdidload before views are laid out. It does adjust to changes in the view size based on quantity of text up to the UIView (UV) edge. However, it will not recognize touches below the original UV bottom edge.
Thanks for any suggestions.
In visual debugger, you can see the UIView in white and the scrollview in blue. The portion of the textview that is white--equivalent to what you see before scrolling--is touchable, while the portion in blue, visible after scrolling, is not.
Related
How can I ensure that a UITextField stays on screen despite not currently viewing the bottom of a UITableView? Like when I scroll up, how can it stay on-screen rather than disappear at the bottom of the screen. I want it anchored to the bottom of the screen at all times.
Edit: It does not appear when I add it as a subview.
2ndEdit: Stop docking post please..
You can add it to view that contains tableView i.e tableView superView.if your viewController has tableView.You can do like
self.view.addSubView(yourTextFied)
self.view.bringSubviewToFront(yourTextFied)
and set the frame of yourTextField approprately
I have a UIScrollView designed with IB.
UIView
UIScrollView
UIView
UITextField
UIButton
...
If I tap on the text field the view scrolls away towards the upper left corner of the screen before the keyboard is appearing. The space above the keyboards remains empty. I can scroll back the view if I drag in this empty space.
I have googled around, but found only postings where users want to scroll UIScrollView. I want the view to stay where it is.
Thanks in advance for any suggestions.
Here's what happened.
You designed the whole thing in Interface Builder.
The scroll view was not scrolling, so you set its contentSize in code to the size of the scroll view's primary subview (what I like to call the content view).
The scroll view was still not scrolling, so you munged the content insets - and this caused the problem that brought you here.
Your mistake was (3). Instead, you should have thought more about (2), i.e., why isn't my scroll view scrolling even though I have given it a nice big content size?
The answer is that, in a storyboard or xib that has auto layout turned on, that's not what you do. What you do is use constraints from the content view to its superview (the scroll view), on all four sides. Set the constant for all four constraints to zero. This causes the content size to match the size of the content view, automatically.
I have a lot of small draggable subviews in my iPad app. I have also a top non-opaque subview with clear color background. It has screen size. User interaction is disabled for it. I need to redraw that top subview while I am dragging one of the bottom subviews. I draw some lines on that top subview. They have to be redrawed according with current bottom subview position. I want achieve smooth dragging but currently I can't. Currently I send a lot of setNeedsDisplayInRect to top view in panMoved of my bottom subview.
How to do that better?
Better to use CALayer of the top subview for drawing. It's much more effective.
i have a scrollView that fits the whole screen. In that View i show some UIImages that scroll horizontally. Like in the PageControl Project from Apple.
Then, when the user taps the screen, i fade in a scrollView at the bottom with some other images. Also horizontally scrolling. Like in the ScrollView Project from Apple.
My problem is, that when i come to the end of the scrollView which was faded in, the upper scrollView also starts to drag. How can i stop that during activation of the second scrollView?
Redraw the frame limits on your first scrollView when the second enters the screen. That way, your touches won't respond to both views. This means you need a container-view to keep both views seperated from each other.
Then you just rescale it back whenever your second scrollView disappears.
Edit: or disable scroll in your first scrollview while the second is open.
As it is set up now, I have two UITextViews inside of a UIScrollView. The point of this is that the UITextViews themselves don't scroll, they just get larger (their contentsize) as more text is added. The UIScrollView handles all of the scrolling up and down of the view regardless of how much text there is (think similar to Mail.app where the subject view is above the message view, etc). That said, I've ran into a problem now. When I programmatically add text to my UITextView (in this code, bodyText), the UIScrollView automatically scrolls to the bottom for some reason.
To add the text I just do:
NSRange selectedRange = [bodyText selectedRange];
NSString *selectedText = [bodyText.text substringWithRange:selectedRange];
bodyText.text = [bodyText.text stringByReplacingCharactersInRange:selectedRange withString:[NSString stringWithFormat:#"<b>%#</b>", selectedText]];
So, for instance, if I had 2000 pixels vertically of text and was currently scrolled to position 400 and then added text somewhere around there, the UIScrollView would then go all the way down to 2000.
I've tried to stop it via subclassing UISCrollView and overriding -setContentOffset, but that freezes all scrolling then.
My question is, why does it scroll all the way to the bottom in the first place? The text is added when the user clicks a button somewhere else on the screen, and the scrolling has nothing to do with any finger drags or anything.
In Scroll View Programming Guide you get:
Making a rectangle visible
It is also possible to scroll a
rectangular area so that it is
visible. This is especially useful
when an application needs to display a
control that is currently outside the
visible area into the visible view.
The scrollRectToVisible:animated:
method scrolls the specified rectangle
so that it is just visible inside the
scroll view. If the animated parameter
is YES, the rectangle is scrolled into
view at a constant pace. As with
setContentOffset:animated:, if
animation is disabled, the delegate is
sent a single scrollViewDidScroll:
message. If animation is enabled, the
delegate is sent a series of
scrollViewDidScroll: messages as
animation progresses. In the case of
scrollRectToVisible:animated: the
scroll view’s tracking and dragging
properties are also NO.
If animation is enabled for
scrollRectToVisible:animated:, the
delegate receives a
scrollViewDidEndScrollingAnimation:
message, providing notification that
the scroll view has arrived at the
specified location and animation is
complete.
So maybe you can use this functionality to lock the visibility on your UITextView.