I have many textfields in my Application which are in a scrollview.
What i need is when user touches on a textfield,
scrollview should scroll in such a way, so that that textfield should not be behind
the keyboard.
I've written a pretty straightforward tutorial on doing this, it mimics as much as possible the behavior of Apple own applications, if it can be of any help:
Adjust UITextField hidden behind Keyboard with UIScrollView
You can use the method - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated in UIScrollView, this should scroll to the offset of the point you give it, you will need to figure out the offset through code
Maybe you could set the text fields' delegates to self, and then adopt the UITextFielDelegate protocol for the class, and then in this method:
- (void)textFieldDidBeginEditing:(UITextField *)textField
Make the scroll view scroll down enough so that you can see the text field.. I don't know how to make the scrollview scroll down though.
Here is a free library for keyboard handling http://www.codeproject.com/Tips/509810/Keyboard-Handling-in-iPhone-Applications. You need write just one line of code:
[AutoScroller addAutoScrollTo:scrollView];
Dont confuse with name AutoScroller. Purpose is same what you asked.
Related
I have a strange issue , I have a page app in which one page I had used a UITextView, but when I tap on the UITextView it moves to the next page, can't write anything on it.
There is no issue when I use UIPageViewControllerTransitionStylePageCurl. The only issue is with UIPageViewControllerTransitionStyleScroll. Anyone know the solution? please help me
I ran into the same issue myself, and it appears that it's a consequence of some default behavior that occurs whenever a UITextField or UITextView becomes first responder inside a UIScrollView.
The solution to prevent your UITextView from scrolling the UIPageViewController is to first embed it into a UIScrollView instead of directly into a page's main view.
This works because when the UITextView becomes first responder it will search for the earliest superview in the view hierarchy that is of type UIScrollView, and it will scroll that scrollview to accommodate for the keyboard covering the screen. If you don't wrap the UITextView inside a UIScrollView, your UIPageViewController's internal UIScrollView will be chosen and scrolled, producing undesired behavior.
You can refer the link below..
UIPageViewControllerTransitionStylePageCurl - http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPageViewControllerClassReferenceClassRef/UIPageViewControllerClassReference.html
UIPageViewControllerTransitionStyleScroll - http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPageViewControllerClassReferenceClassRef/UIPageViewControllerClassReference.html
Currently, I'm displaying vertical section scrollbar in my table view:
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
return [SectionModel getAllSectionNames];
}
I need to zoom-in the section name that is tapped on scrollbar, and zoom-in a little bit previous and next section names. The desired effect should be similar to DOCK behavior in MAC OS X. Any suggestions where to start?
UPDATE: Currently, I'm trying to find any scroll-to-section event but with no luck. UIScrollViewDelegate do not have such method.
Currently, I have realized that it's impossible to do that with native Apple methods. You need to implement that scrollbar from scratch.
Another option would be to use UIScrollViewDelegate method sectionForSectionIndexTitle:atIndex: that gets called when you tap on concrete section on scrollbar.Then you might create custom UIView with zoomed-in letter and present it on tableviews superview (for example at center). It's not the desired effect but some workaround.
I think have decent experience working with iPhone development.
as much I know.. I did set up the delegate..
I have from top to botton
UIView --> UIScrollView--> UITextView
I tried everything... to get the event scrollView to fire the scrollViewDidScroll event.
is anything wrong with the structure..
there not much of the code to post here.
what I am trying to do is.. do something when UITextView is scrolled.
Sorry did not respond... Just wanted to share in case anyone need this...
I used delegate methods of parent i.e. UIView for UIScrollView i.e. Child it worked..
It's hard to say without some code or a screenshot. Is the scroll view actually scrolling? If you set it up in Interface Builder, did you change the size of the scroll view's contentSize in code so that it can actually scroll? Maybe the text view is eating the scroll events; did you try setting the text view's delegate to see if it's firing a scrollViewDidScroll event?
Ok. I have made a custom cell for my table, and it contains a text view. When I have multiple lines in the text view, I can scroll up and down, but in doing this the table also scrolls. How can I stop this behaviour? If anyone needs parts of my code or further details, please just ask. I am more than willing.
Thank you for your help
I suggest you to move text edit (write) behavior to another view controller. If you need read-only functionality from it then just increase cell and textView height.
Did you try setting canCancelContentTouches to NO? It's a property of UIScrollView, from which UITableView inherits.
Your custom cell seems to pass on touch events to its container class as well as utilizing them itself. Did you implement any - touchesBegan:, - touchesMoved: or - touchesEnded:?
If you make use of a touch events, you should not pass them on in the responder chain.
When the text view has focus, set scrollEnabled=NO on the table view. You may have to manually remove focus from the text view and restore scrolling when a touch occurs outside the text view.
The latest version of Apple's UICatalog example application includes zero code in the TextFieldController for handling keyboard show/hide events, and yet the table view still slides up and down beautifully with the keyboard.
Does anyone know what the new trick is? Are there settings in the XIB that allowed them to forgo registering for the notifications or using TextField delegate methods?
The TextViewController still uses keyboard notifications to deal with view sliding, so I'm really confused as to why this isn't included for TextFields anymore.
Thoughts?
You can close the keyboard, if it's open by calling:
[sender resignFirstResponder];
Not sure about opening the keyboard however.
The trick is hidden within calling becomeFirstResponder on a UITextField that is in a scrollable view. Apparently, whenever calling [textField becomeFirstResponder], iOS automatically scrolls the parent view until said textField is visible.
This behavior can actually be undesirable in some cases, as it will not usually scroll to the same location that the UIScrollView method scrollRectToVisible:animated: would if you were to try to do things that way.
Thanks for your thoughts everyone!