Disable Uiscrollview Scrolling When Uitextfield Becomes First Responder

Unwanted automatic scrolling with UIScrollView and UITextFields as subviews

Not an answer to your question, but it should fix the problem:

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
// Make the text field first responder...
}

How to make a UIScrollView auto scroll when a UITextField becomes a first responder

I hope this example will help you
You can scroll to any point by this code.

scrollView.contentOffset = CGPointMake(0,0);

So if you have textfield, it must have some x,y position on view, so you can use

CGPoint point = textfield.frame.origin ;
scrollView.contentOffset = point

This should do the trick,

But if you don't know when to call this code, so you should learn UITextFieldDelegate methods

Implement this method in your code

- (void)textFieldDidBeginEditing:(UITextField *)textField {
// Place Scroll Code here
}

I hope you know how to use delegate methods.

iOS: Stop ScrollView from making room when selecting textfield at top

Try embedding your text field in a scroll view the same size as your text field.

The reason why this should work is because when a text field becomes first responder, it only scrolls the scroll view that is its most recent ancestor in the view hierarchy. If it only finds the dummy scroll view, whose content size should not exceed its bounds size, then no scrolling should occur in either scroll view.

Can I override scroll view's automatic behavior to scroll to the first responder?

I didn't test this particular situation, but I've managed to prevent a scrollview from bouncing at the top and bottom by subclassing the scrollview and overriding setContentOffset: and setContentOffset:animated:. The scrollview calls this at every scroll movement, so I'm fairly certain they will be called when scrolling to the textfield.

You can use the delegate method textFieldDidBeginEditing: to determine when the scroll is allowed.

In code:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
self.blockingTextViewScroll = YES;
}

-(void)setContentOffset:(CGPoint)contentOffset
{
if(self.blockingTextViewScroll)
{
self.blockingTextViewScroll = NO;
}
else
{
[super setContentOffset:contentOffset];
}
}


-(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
{
if(self.blockingTextViewScroll)
{
self.blockingTextViewScroll = NO;
}
else
{
[super setContentOffset:contentOffset animated:animated];
}
}

If your current scroll behaviour works with a setContentOffset: override, just place it inside the else blocks (or preferably, in a method you call from the else blocks).

Moving uiTextField With ScrollView - Scroll stop working

In keyboardWillBeShown() method setcontentSize: -

backgroundScrollView.contentSize = CGSizeMake(0, 600)

0 "width" means -> Dont scroll in x direction

600 "height" means -> Scroll content can be scroll upto 600 height



Related Topics



Leave a reply



Submit