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
How to Catch "Index Out of Range" in Swift
Get the Current Scroll Position of a Swiftui Scrollview
How to Pass Data Between View Controllers in Swift
Didselectrowatindexpath Not Working, Swift 3
Uitableviewcell, Show Delete Button on Swipe
Difference Between Uiviewcontentmodescaleaspectfit and Uiviewcontentmodescaletofill
How to See Saved Nsuserdefaults
How to Simultaneously Satisfy Constraints, Will Attempt to Recover by Breaking Constraint
Delete Keychain Items When an App Is Uninstalled
Proper Use of Beginbackgroundtaskwithexpirationhandler
Ios 6: How to Restrict Some Views to Portrait and Allow Others to Rotate
How to Load Local HTML File into Uiwebview
Uicollectionview - Dynamic Cell Height
Swift Get Request With Parameters
How to Play Audio in Background With Swift
How to Compress of Reduce the Size of an Image Before Uploading to Parse as Pffile? (Swift)
Is There a Good Charting Library For Iphone
How to Reload Data in a Tableview from a Different Viewcontroller in Swift