Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TPKeyboardAvoiding with fullscreen UITextView doesn't work correctly #58

Open
gcastaldi opened this issue Oct 24, 2013 · 6 comments
Open
Labels

Comments

@gcastaldi
Copy link

Hi,
I've created a simple project with a main view that contains:
UIView -> TPKeyboardAvoiding -> UITextView
When you write in the UITextView the cursor goes below the keyboard like I'm using a simple UIScrollView.
You can download it at https://github.com/gcastaldi/AvoidKbHelloWorld.git.

Thanks.
Giannandrea

@JamalK
Copy link

JamalK commented Dec 22, 2013

I have the same issue with my project. Please help!

@YSDC
Copy link

YSDC commented Jan 19, 2014

I also have an issue with textview support.

After some textfield I have a textview. It appears that doing multiple return line in the textview result in a bad state where the scrolling view became shorter, and i cannot reach the end of my table view. Even if i try to disable return line in my textview the problem still exist.

@jungchris
Copy link

I've come across what seems like a similar problem with a full view UITextView set up with standard hierarchy of ViewController -> UIScrollView (TPKeyboardAvoidingScrollView) -> UITextView. I did not see the method that is able to recognize in what area of a UITextView the user is interacting, but I didn't look at all the classes. Has anyone been able to resolve this issue since it was opened more than a year ago?

@haojianzong
Copy link

I have come across this issue as well, but it turns out be a stupid mistake. I have used a wrong class for my scrollView. There are a few available classes from this repo:

  • TPKeyboardAvoidingScrollView
  • TPKeyboardAvoidingTableView
  • TPKeyboardAvoidingCollectionView

It is easy to mis-type the class name in storyboard, and the compiler will not complain about it. So please double check it.

@jungchris
Copy link

As haojianzong mentions double check the class for the scrollview. Adding a "container" view in the case of a ScrollView with constraints set to the superview is also a good practice as follows: ViewController -> UIScrollView (TPKeyboardAvoidingScrollView) -> UIView (container for UI elements) -> UITextView. If you want vertical scrolling set the height constraint to be '>='.

@LeoSnek
Copy link

LeoSnek commented Oct 14, 2020

I have got this working nicely, including respecting safe areas, so wanted to share some code to help others. This uses the same structure as mentioned by @jungchris above.

Firstly make sure to set the following properties:

scrollView.contentInsetAdjustmentBehavior = .always
textView.isScrollEnabled = false

The set up the constraints as follows:

NSLayoutConstraint.activate([
    scrollView.topAnchor.constraint(equalTo: view.topAnchor),
    scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
    scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
    scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
        
    containerView.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor),
    containerView.leadingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.leadingAnchor),
    containerView.trailingAnchor.constraint(equalTo: scrollView.contentLayoutGuide.trailingAnchor),
    containerView.bottomAnchor.constraint(equalTo: scrollView.contentLayoutGuide.bottomAnchor),
    containerView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor),
     
    textView.topAnchor.constraint(equalTo: containerView.topAnchor),
    textView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor),
    textView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
    textView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor)
])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants