Comments (13)
Having the same problem, trying to figure out what is going on...
from chats.
i third this, i'm having the same dilemma
from chats.
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.
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.
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.
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.
i keep running into layout constraint problems :/
from chats.
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.
i did ..and haven't gotten help
from chats.
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.
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.
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.
@bryankattah see issue #60.
from chats.
Related Issues (20)
- tableView does not scroll after message send HOT 2
- Update Repository Description with technology specifics HOT 2
- Chats/MessageBubbleCell.swift:89:31: Extra argument 'scale' in call HOT 1
- error occurs when I copy try to paste copied message into textbox HOT 1
- Integrate with Lets Chat HOT 1
- Scrolling is glitchy HOT 1
- XCode 6.3 support
- Add Chats-Android Client HOT 9
- Add Chats-Web Client HOT 2
- how can get the code when sign up HOT 5
- Question HOT 2
- git clone error HOT 4
- App crash on iPhone4s with iOS version 7.1 HOT 1
- When I pull the code with git , some files missing HOT 1
- switch database to Nosql HOT 1
- Can not run on iphone 6 with iOS 9.3 HOT 2
- It doesn't work with Swift 3 and Xcode 8 HOT 1
- main storyboard HOT 1
- Failed to recurse into submodule path 'Clients/iPhone' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chats.