Giter Site home page Giter Site logo

Comments (13)

vrwim avatar vrwim commented on August 19, 2024

Having the same problem, trying to figure out what is going on...

from chats.

Joropo avatar Joropo commented on August 19, 2024

i third this, i'm having the same dilemma

from chats.

vrwim avatar vrwim commented on August 19, 2024

A solution that I have found is creating an NSLayoutConstraint with a height that you calculate from the content of the textbox. (in the shouldChangeTextInRange method of UITextViewDelegate)
See this answer of mine on stackoverflow: http://stackoverflow.com/a/29104626/1009013

from chats.

Joropo avatar Joropo commented on August 19, 2024

did you make the constraint programmatically or via storyboard? do you know if it's possible to have autolayout on strictly one view?

from chats.

vrwim avatar vrwim commented on August 19, 2024

I made mine in code, as it's easier there, I don't really know how to disable a constraint in a storyboard (never tried).

I guess having autolayout on one view could be possible, I don't know, I use autolayout for everything...

from chats.

Joropo avatar Joropo commented on August 19, 2024

ok awesome, where did you put that function in the acani code? also would you mind putting your constraint code? i'm fairly new to constraints in general, and would like to see how you did it. Also, is it possible to only have a constraint on the text field and nothing else? thank you so, so much!

from chats.

Joropo avatar Joropo commented on August 19, 2024

i keep running into layout constraint problems :/

from chats.

vrwim avatar vrwim commented on August 19, 2024

I didn't fix it in this code, I did it in mine. If you need help with something, ask it on www.stackoverflow.com and not here.

from chats.

Joropo avatar Joropo commented on August 19, 2024

i did ..and haven't gotten help

from chats.

Xendrez avatar Xendrez commented on August 19, 2024

Here's what I did in addition to @vrwim 's solution:
First I added a height constraint:

    self.textFieldHeightLayoutConstraint = NSLayoutConstraint(item: textView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 28)
    self.toolBar.addConstraint(textFieldHeightLayoutConstraint)

I changed the updateTextViewHeight method to work with the constraint:

    func updateTextViewHeight() {
        let oldHeight = textView.frame.height
        let newText = textView.text
        let newSize = (newText as NSString).boundingRectWithSize(CGSize(width: textView.frame.width - textView.textContainerInset.right - textView.textContainerInset.left - 10, height: CGFloat.max), options: .UsesLineFragmentOrigin, attributes: [NSFontAttributeName: textView.font], context: nil)
        let heightChange = newSize.height + textView.textContainerInset.top + textView.textContainerInset.bottom - oldHeight

            let maxHeight = self.view.frame.height
            - self.topLayoutGuide.length
            - currentKeyboardHeight
            + toolBar.frame.height
            - textView.textContainerInset.top
            - textView.textContainerInset.bottom
            - 20

            if !(textFieldHeightLayoutConstraint.constant + heightChange > maxHeight){
                //ceil because of small irregularities in heightChange
                self.textFieldHeightLayoutConstraint.constant = ceil(heightChange + oldHeight)

                //In order to ensure correct placement of text inside the textfield:
                self.textView.setContentOffset(CGPoint.zeroPoint, animated: false)
                //To ensure update of placement happens immediately
                self.textView.layoutIfNeeded()

            }
            else{
                self.textFieldHeightLayoutConstraint.constant = maxHeight
            }

    }

Finally, I added the following to KeyboardDidShow method in order to support both landscape and portrait:

    //the var recentlyTransitionedSize is set within the viewWillTransitionToSize method
    if self.recentlyTransitionedSize == true {

            //Because notifications happen on background threads, any UI-changes has to be done on the main thread.
            dispatch_async(dispatch_get_main_queue(), {
                self.updateTextViewHeight()
            })
            self.recentlyTransitionedSize = false
        }

I hope this helps someone!

from chats.

kos9kus avatar kos9kus commented on August 19, 2024

I've looked into that problem, it seems the UIToolbar has an intrinsic size that doesn't permit change its frame explicitly. Solving a problem through a constraint it's not so elegant in that case, I'd say.
Does anyone know how to change intrinsic size of UIToolBar explicitly??

from chats.

bryankattah avatar bryankattah commented on August 19, 2024

hi there, I am new to swift and I was just taking a look at the Chat Xcode project but can't find the main.storyboard. can you show me how to navigate to it

from chats.

ma11hew28 avatar ma11hew28 commented on August 19, 2024

@bryankattah see issue #60.

from chats.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.