I've read a lot of material on this topic but most of them create custom view programatically.
Is it possible to use InputAccessoryView with a custom view created in IB? In storyboard I've added textInputView, inside which I've added text view and send button etc as seen in the screenshot below.
I've following code so which removes Table View for some reason so I can't get it working. I've added tableview in the storyboard.
I've shown here only InputAccessoryView related code.
class InputAccViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
#IBOutlet weak var tableView: UITableView!
#IBOutlet weak var textView: UITextView!
#IBOutlet weak var textInputView: UIView!
// other code
override var canBecomeFirstResponder: Bool { return true }
override var inputAccessoryView:UIView {
get{
return self.textInputView
}
}
override func viewDidLoad() {
super.viewDidLoad()
textInputView.removeFromSuperview()
// other code
}
// other code tableview delegates etc...
}
Left screenshot is with the accessory view code which doesn't show table view. If I comment out accessory view related code it does show table view as in the right screenshot.
Seems you might be constraining the UITableView's bottom to the textInputView's top. When you are setting the textInputView as the inputAccessoryView of the UIViewController this no longer works as expected. When setting the textInputView as the inputAccessoryView make sure you constraint the bottom of UITableView to the bottom of UIViewController's view.
Related
I've been checking out various tuts on how to move table view up/down with keyboard interactively when using InputAccessoryView but I didn't find any solution. Most of the solutions suggest using keyboard notifications which defeats the purpose of having InputAccessoryView for me. I started using InputAccessoryView only to avoid kb notifications as drag to dismiss keyboard interactively was difficult to implement using kb notifications.
How do we move table view up and down with InputAccessoryView? Any hint will do as I already know how to move table view up and down with kb notifications.
Storyboard setup -> https://i.stack.imgur.com/0QJyn.png
Screen recording -> https://imgur.com/a/S5Oi9VS
Snippet of relevant code
class InputAccViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
#IBOutlet weak var tableView: UITableView!
#IBOutlet weak var textView: UITextView!
#IBOutlet weak var textInputView: UIView!
// other code
override var canBecomeFirstResponder: Bool { return true }
override var inputAccessoryView:UIView {
get{
return self.textInputView
}
}
override func viewDidLoad() {
super.viewDidLoad()
textInputView.removeFromSuperview()
// other code
}
// other code tableview delegates etc...
}
While facing the same issue a while back I found a simple solution that worked for me. I'm putting it here so that it could be helpful for others too. What I did was just replace the UIViewController with a UITableView constraint all sides to the UIView subclass view with just a UITableViewController and use the tableView that is in build into it to populate the data. All the moving content above the keyboard feature is built right into UITableViewController. Since I did my layout programmatically it was pretty easy for me to try this out and make it work. You seem to have done it via a storyboard try this out for yourself and you'll feel relieved by the result. By the end this is implemented your code should look from this:
class InputAccViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
#IBOutlet weak var tableView: UITableView!
To this:
class InputAccViewController: UITableViewController {
// `#IBOutlet weak var tableView: UITableView!` removed
}
I am working on a sample to display images inside scroll. The image is loading fine but then it allows me to drag the image up and down inside the scroll. I would still want to be able to move right and left (horizontally), but the image should be fixed from moving vertically.
The scroll view and the image constraints are set to the top, bottom, left and right as those of the main view.
What am I doing wrong?
This is my code and storyboard settings
import UIKit
class Image2ViewController: UIViewController, UIScrollViewDelegate {
#IBOutlet weak var scrollView: UIScrollView!
#IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.scrollView.contentSize = (imageView.image?.size)!
}
}
and these are my storyboard settings for ScrollView and ImageView. The top 2 are for the scroll and other 2 are for the image.
Adding this line in the viewDidload solved the issue:
self.automaticallyAdjustsScrollViewInsets = false
I have a bottomView with opacity set to 0.65, and embedded in that View I have 5 buttons - which also gets the 0.65 opacity attribute - but How do I make the buttons get rid of the opacity?
I want the buttons to be very clear
I have tried to make outlets of the View and the Buttons and set the buttons to the front - view, but it doesn't change the appearance of the button??
#IBOutlet weak var bottomView: UIView!
#IBOutlet weak var findVejOutlet: UIButton!
#IBOutlet var superViewOutlet: UIView!
#IBAction func findVejButton(_ sender: Any) {
superViewOutlet.bringSubview(toFront: findVejOutlet)
}
override func viewDidLoad() {
super.viewDidLoad()
settingView()
}
func settingView(){
bottomView.bringSubview(toFront: findVejOutlet)
}
If you set the opacity of a view to a value of less than 1, it makes all the contents of a view partly transparent (including subviews). You can't change that, and opacity has nothing to do with the front-to-back ordering of the views.
You either need to make the parent view fully opaque and the non-button subviews partly transparent, or remove the buttons from the translucent view and instead put them in the common parent view.
I have the following screen (image) which shows a side menu when the button is pressed the menu appears, plus I have a uitableview to show other things
my problem is that when the side menu appears the uitableview is resized.
How do I keep my uitableview intact?
I've been trying the next but I have not got anything:
#IBOutlet weak var Vmenu_usuario: UIView!
#IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
view.sendSubview(toBack:tableView)
view.bringSubview(toFront:Vmenu_usuario)
}
If you want to delete White space view over tableview
uncheck the option 'Adjust Scroll View Insets'.
more detail: Empty white space above UITableView inside a UIView
Hope this hellp.
I am new to swift and am trying to add a UIScrollview to a custom UITableViewCell. I can't seem to get the scrollview to scroll in the simulator though. I have tested both vertical and horizontal scrolling.
Here is the code for my custom UITableViewCell
import UIKit
class CustomTableViewCell: UITableViewCell, UIScrollViewDelegate {
#IBOutlet weak var winLoseValueLabel: UILabel!
#IBOutlet weak var dateLabel: UILabel!
#IBOutlet weak var newTotalLabel: UILabel!
#IBOutlet weak var locationLabel: UILabel!
#IBOutlet weak var playersLabel: UILabel!
#IBOutlet weak var playersScrollView: UIScrollView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.playersLabel.text = nil
//self.playersScrollView.contentSize.height = 1000
self.playersScrollView.contentSize.width = 1000
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func addLabelToScrollView(str : String) {
if self.playersLabel.text == nil{
self.playersLabel.text = str
}
else{
self.playersLabel?.text = self.playersLabel.text! + "\n\(str)"
}
}
}
My playersScrollView outlet has been properly connected to the scrollview in my storyboard. As far as I can see from all of the tutorials and sources online, I should just have to set the contentSize width or height (larger than the view area) to get it to scroll, which I have done in the awakeFromNib function.
Any ideas why this is not working in the simulator? Secondly, ideally I would like to have a vertical scrolling scrollview in the table cell, but I thought that the table view's vertical scrolling might have been interfering with the scrollview, so I changed it for horizontal scrolling for testing, which also didn't work.
Can you have a vertical scrollview in a vertically scrolling UITableView, or will the table view scrolling interfere too much with the scrollview?
Ok, it turns out that the constraints on my playersLabel, which is a subview of playersScrollView, was the culprit, although I am not sure why. I adjusted the constraints on the label and that allowed the horizontal scrolling to work.
The vertical scrolling still did not work, so I had to override the touchesBegan and touchesEnded methods in the scroll view so I could disable/re-enable the scrolling of the table view.