Ensure UITextField stays onscreen despite scrolling - ios

How can I ensure that a UITextField stays on screen despite not currently viewing the bottom of a UITableView? Like when I scroll up, how can it stay on-screen rather than disappear at the bottom of the screen. I want it anchored to the bottom of the screen at all times.
Edit: It does not appear when I add it as a subview.
2ndEdit: Stop docking post please..

You can add it to view that contains tableView i.e tableView superView.if your viewController has tableView.You can do like
self.view.addSubView(yourTextFied)
self.view.bringSubviewToFront(yourTextFied)
and set the frame of yourTextField approprately

Related

IOS/autolayout: Detect touch event below visible view of scrollview

I have been struggling with how to detect touches on a portion of a tall textview subview that extends below the visible view of a screen.
The view hierarchy looks like this:
View Controller
UIView (UV,visible portion of screen)
UIScrollView (SV)
UIView (CV,Content View--contains all elements)
UITextView (TV)
When the screen first loads, a portion of the textview (TV) is visible, the portion contained within the UV, or visible portion of the screen. When you scroll, you move the scrollview (SV) behind the visible portion of screen, revealing portions of the textview that are outside the original UIView (UV).
When you scroll down, while you can see the lower portions of the textview, they do not respond to touches.
Can anyone suggest a way to make an entire textview reponsive to touches even, portions of the textview that extend below the visible UIVIew?
Do I need to make UIVIew (visible portion of screen) bigger than the actual phone screen? Or what can I do.
Of note, the gesture recognizer is currently added to the view in viewdidload before views are laid out. It does adjust to changes in the view size based on quantity of text up to the UIView (UV) edge. However, it will not recognize touches below the original UV bottom edge.
Thanks for any suggestions.
In visual debugger, you can see the UIView in white and the scrollview in blue. The portion of the textview that is white--equivalent to what you see before scrolling--is touchable, while the portion in blue, visible after scrolling, is not.

UIScrollView automatically scrolls to next subview horizontally then bounces somewhere else

UIScrollView has several UILabel subviews, which are set to scroll horizontally (think about Instagram filters scrolling view). I can scroll UIScrollSubview, act upon tapping on a UILabel subview. Next thing I would like to achieve is to programmatically scroll to an invisible UILabel subview, when the users selects the last visible subview on the right (similar to how the instagram filters scroll out of the visible area when the user selects the last visible filter).
When the user touches the last visible UILabel subview, I execute
[_scrollView setContentOffset:CGPointMake(64, 0) animated:YES];
where 64 is the width of every UILabel subview of the scrollView.
This works fine only on the first selection event of the last visible subview. Once the scrollView scrolled to reveal the desired subview on the right side of the selected one, and I select newly revealed subview, the scrollView correctly scrolls to the left revealing the next invisible subview, but then jumps back (to the right) two positions (128). The desired behaviour is to always scroll to the left when the last visible subview on the right is selected (right now this happens only on the first selection).
Any suggestions would be appreciated.
Thanks.
EDIT: The bouncing issue went away in 2 cases:
scrollView.pagingEnabled: NO;
user performs relatively long touches on subviews
You should add 64 to the current contentOffset.
[_scrollView setContentOffset:CGPointMake(_scrollView.contentOffset.x + 64, 0) animated:YES];

iOS 7.1 Why is my UIScrollView scrolling away on showing keyboard?

I have a UIScrollView designed with IB.
UIView
UIScrollView
UIView
UITextField
UIButton
...
If I tap on the text field the view scrolls away towards the upper left corner of the screen before the keyboard is appearing. The space above the keyboards remains empty. I can scroll back the view if I drag in this empty space.
I have googled around, but found only postings where users want to scroll UIScrollView. I want the view to stay where it is.
Thanks in advance for any suggestions.
Here's what happened.
You designed the whole thing in Interface Builder.
The scroll view was not scrolling, so you set its contentSize in code to the size of the scroll view's primary subview (what I like to call the content view).
The scroll view was still not scrolling, so you munged the content insets - and this caused the problem that brought you here.
Your mistake was (3). Instead, you should have thought more about (2), i.e., why isn't my scroll view scrolling even though I have given it a nice big content size?
The answer is that, in a storyboard or xib that has auto layout turned on, that's not what you do. What you do is use constraints from the content view to its superview (the scroll view), on all four sides. Set the constant for all four constraints to zero. This causes the content size to match the size of the content view, automatically.

UITableView stops scrolling enough after I add/remove a view to the superview of table view

Here is the problem that I'm facing. I have UITableView inside main view. When user taps menu button, view is added to the view hierarchy of superview, and this view covers all screen, except the menu button. That is I call
[self.view insertSubview:self._menuView belowSubview:self._menuButton]
After user clicks the menu button again I call
[self._menuView removeFromSuperview]
However, after this, the UITableView stops scrolling, actually it scrolls, but just a little, couple of pixels, and then bounces back to the location on which it was before I inserted _menuView. I've monitored the menu hierarchy after inserting and removing the _menuView, it is actually removed, and also there is no view which covers the UITableVIew, so there is no chance that some other view steals touches from UITableView. What can be the problem? Any ideas?
EDIT 1: I've noticed besides not being able to scroll, another strange thing happens. When I show menuView, the tableView is scrolled to top, without animation. (the menuView is half opaque only, so I can see the tableView underneath it)
EDIT 2: I've monitored contentSize and contentOffset of tableView before and after inserting _menuView, the reason for not being able to scroll is that somehow contentSize is being changed.
TABLE VIEW BEFORE INSERTING MENU - contentSize:{Width=320, Height=10519} contentOffset:{X=0, Y=3980}
TABLE VIEW AFTER INSERTING MENU - contentSize:{Width=320, Height=44} contentOffset:{X=0, Y=0}
As You can see, the height is changed to 44 that's why I'm not able to scroll. And Also, as I've said in EDIT 1: tableView is scrolled to top - so as you can see contentOffset is also zeroed. Any ideas why content size changes automatically?
Thanks in advance.
i think there is problem with your tableview frame. right after removing subview, try to set frame of your tableview at its original frame.may this will solve your problem
Content in the UITableView organized automaically and designed only to show cells & header/footer elements. To proper working you should wrap your table into parentView and add your menu to that parentView rather than to the UITableView. You can also try to call reloadData method on table since it can restore the content size of the view.

horizontal scrolling of a scrollView in a scrollView - small problem

i have a scrollView that fits the whole screen. In that View i show some UIImages that scroll horizontally. Like in the PageControl Project from Apple.
Then, when the user taps the screen, i fade in a scrollView at the bottom with some other images. Also horizontally scrolling. Like in the ScrollView Project from Apple.
My problem is, that when i come to the end of the scrollView which was faded in, the upper scrollView also starts to drag. How can i stop that during activation of the second scrollView?
Redraw the frame limits on your first scrollView when the second enters the screen. That way, your touches won't respond to both views. This means you need a container-view to keep both views seperated from each other.
Then you just rescale it back whenever your second scrollView disappears.
Edit: or disable scroll in your first scrollview while the second is open.

Resources