I have a UITextView
and a simple blank view with UIPanGestureRecognizer
in it. The idea behind this was the following: I make a pan gesture in blank view, gesture recognizer detects it and scrolls the text view (by scrollToVisibleRect
or smth like that). Is there any other way? I am asking because this is not resolved yet.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
You can set the content offset of your textView, just like any other scrollView. Try something like this:
I haven't tested this, so there might be some small issues. This should at least get you pointed in the right direction. Let me know if you have updates/questions.
Basically, Logan's answer is right. Although, I would like to add this: You need to subtract(not add) the y component of translation. So the code should look like this:
And then you must prevent
contentOffset
's being more than your textView'scontentSize.height
.Just add this:And yes,this line is VERY important
Why? Apple says in the :
- (CGPoint)translationInView:(UIView *)view
The x and y values report the total translation over time. They are not delta values from the last time that the translation was reported. Apply the translation value to the state of the view when the gesture is first recognized—do not concatenate the value each time the handler is called.
For further info, you'd better read this.