How to reposition UITextField up without a Scroll View - ios

I have the following issue:
I have a parent view. Inside this is a scroll view with different text fields and labels. When a text field is being edited, I reposition the text field to the top of the screen so that the keyboard does not hide the textfields.
One of the text fields has a table view below it which is used a dropdown. when text is entered, it shows various results dynamically. This table view is also added to the scrollview. This is not a recommended and also does not work. So how can I achieve this whitout using scrollview?

As #hackerinheels has mentioned above, use this method to reposition elements, so that the keyboard does not obstruct your text fields.
Avoid using scrollview for repositioning, as adding tableview inside scrollview is problematic.
Xcode/iOS5: Move UIView up, when keyboard appears

Related

Swift, iOS - have button move up when clicked to display text field? Then move back?

I know how to accomplish this in something like sprite kit but with just a normal ViewController I'm a little lost - right now I have my button and my UITextfield set up on my xib file. Right now, when the button is clicked my textfield goes from hidden to not, which is great.
Problem is I need to have my button slide up (as in animate up) to "reveal" the text field when clicked. As in the textfield would be underneath the button. When another button is clicked, I want the button to slide back down to its original position. I don't know how to implement these animations.
Here is an image of what I need:
So the blue button would trigger the move up when clicked. Then if another button is pressed the blue button moves back to original position over textfield.
How can I accomplish this?
Here's an option you can try if you aren't displaying these in a UITableView:
Setup your .xib with all of the possible views in an 'expanded' state. Give your views that will be revealed a height constraint (in addition to the others needed to layout the view properly), and then create an outlet for those height constraints in your view controller. Additionally, store a reference to what you want the expanded height of the view to be in your view controller.
In viewDidLoad of your view controller you will set those height constraints' constant values to 0. This will cause these views to effectively disappear, and your other views should fill in the gaps they leave behind based on their constraints.
When one of your buttons is pressed, you'll update which views should be visible by setting their height constraint to 0 if you want them hidden, or to the value you saved earlier if you want them shown. After the height has been updated, call
UIView.animateWithDuration(howLongTheAnimationLasts) {
self.view.layoutIfNeeded()
}
which should animate the change in height values.
Alternatively, you could try putting your options in a UITableView and altering their height using tableView:heightForRowAtIndexPath: and reloading the cells when their heights should change.

iOS: How can I remove reference to sub-views?

I'm creating an app that has hundreds of view controllers in interface-builder. Each of these view controllers has a button with a code number. When the button is pressed I want the button to expand and show a few lines of text describing the code number. The problem is that the button is placed within a subview that acts as a frame for the button. Therefore, the expanded button size is going to be constrained to that subview and the text will be cutoff. Is there a way for me to programmatically remove the reference to the sub-view? I can do this in interface-builder, but like I said there are hundreds of these view controllers.
Instead I removing it you could expand the subView's and the UIButton's width. That would allow the button to expand as you'd like it to and you would not have to remove the subViews.

UIButtons not working in Scroll View

I have a Scroll View with a View (content view) inside of it. I've added two buttons to test. The Scroll View scrolls fine but the buttons within the content view are not clickable. I've seen plenty of posts saying this issue happens when they programmatically add UIButtons to the View, but I am not doing this. Here is my exact process:
Drag the Scroll View onto the main view. Add 4 constraints
Drag the Content View onto the Scroll View. Add 4 constraints.
Add 2 Buttons (one high and one low to test scrolling) to the Content View.
This is all I am doing, no code at this point. Is there anything else I have to do to allow the buttons to be clicked? Here is a screenshot of my xib:
Update:
When hooking the button up to a simple IBAction and logging a message, it turns out it IS being pushed and working properly. However, when the button is pushed, the button isn't changing colors like it should (its "pressed" state is not appearing). Any ideas why?
First make the button to custom type
Select button from storyboard then on right attributed inspector change its "state config" to whatever you need like Highlighted, selected, Disabled and default and choose the colour for each state.
Now you can see the colour change on that button.
A UIScrollView first needs to know whether or not you are going to scroll before letting the touch pass to its child views. If you want the child views to get the touch immediately, set the UIScrollView's delaysContentTouches to NO.

How to hide a TextFields from multiple TextFields and set layouts or frame of other TextFields to remove space of hidden textfield?

I have been facing a problem since using auto layout. Before auto layout making multiple TextFields on a UIView removing it by using code was very simple.But now a days, its very crucial to remove a TextField(UIButton,UIlabel) from multiple in a view and reset other TextFields by removing space of hidden TextFields.
So, can any one help me to hide a TextField from a view and reset other TextField by removing to space. In below image you can see my requirement-> I want to hide second TextField and rearrange below controls by managing(removing second TextField space)space and setting auto layouts of all below controls.
Please help me.

ipad - Move UITextview to top when keyboard is active

I have UITextView in my iPad app and I need to move it to top, when keyboard appears
. Can you help me how to do it? Thanks
An extract from here :Apple documentation
Moving Content That Is Located Under the Keyboard When asked to
display the keyboard, the system slides it in from the bottom of the
screen and positions it over your application’s content. Because it is
placed on top of your content, it is possible for the keyboard to be
placed on top of the text object that the user wanted to edit. When
this happens, you must adjust your content so that the target object
remains visible.
Adjusting your content typically involves temporarily resizing one or
more views and positioning them so that the text object remains
visible. The simplest way to manage text objects with the keyboard is
to embed them inside a UIScrollView object (or one of its subclasses
like UITableView). When the keyboard is displayed, all you have to do
is reset the content area of the scroll view and scroll the desired
text object into position. Thus, in response to a
UIKeyboardDidShowNotification, your handler method would do the
following:
Get the size of the keyboard. Adjust the bottom content inset of your
scroll view by the keyboard height. Scroll the target text field into
view.

Resources