Scrollview is bouncing back - iphone

I have a app where in once I tap on a textfield it slides on top of keyboard.
My scrollview is bouncing back when I scroll down my content. iPhone documentation says "by default, it “bounces” back when scrolling exceeds the bounds of the content."
Any clue how to get rid of this? Should I increase the content size of scrollview?

If you want to stop a UIScrollView from bouncing:
UIScrollView *myScrollView; ...
[myScrollView setBounces:NO];
If your question was about the scrolling behavior being different when the keyboard is on screen, double check that you have set the autoresize behavior of the Views appropriately.

Related

iOS UIScrollView in UIWindow

I currently am making an iOS project in which I have a UIScrollView as a direct subview of a UIWindow (using [window addSubview:scrollView];). The window's frame and its content are being set properly, and the contentSize is set to be bigger than the window's frame. When I try to scroll the UIScrollView, it doesn't scroll at all. Both scrollEnabled and pagingEnabled are set to YES, but the scrollview doesn't scroll, which leads me to believe that the touch/scroll events are not even being received by the scroll view. The window has a UITapGestureRecognizer added to it if it makes any difference. Do I need to somehow forward the swipe events to the UIScrollView, or is there a different reason that it's not scrolling?
EDIT: Here's some code.
float count=ceil([self.msgArray count]/2); //msgArray has length of 3+, NSLog()'d and confirmed.
float contentHeight=97.5 * count;
[dataScrollView setContentSize:CGSizeMake(320,contentHeight)];
dataScrollView.userInteractionEnabled=YES;
dataScrollView.pagingEnabled=YES;
dataScrollView.scrollEnabled=YES;
dataScrollView.clipsToBounds=YES; //Have also tried with this set to NO, or not set at all.
//Add subviews to dataScrollView.
EDIT: Here's some more info.
contentHeight is 195.00 when logged. I've removed the delegate method and I am back to using direct subviews of the scroll view. The window's height is 97.50.
EDIT: I've also removed the UITapGestureRecognizer from the UIWindow, but the scrollview still doesn't scroll.
Ah, the UITapGestureRecognizer! This might be a bug that took me hours to figure out in my own project. Is its cancelsTouchesInView property set to NO like it should be? (YES is the default... It can really throw you off if you're not expecting it.)
Just log the scrollview bounds width/height. The content height you are setting should be greater than the scrollview height. If its more then the scroll view automatically enables its scrolling.

How do I stop a UIScrollView from automatically scrolling when a UITextField is touched out of the scrollview's frame?

By default, if a textfield is a child of a scrollview and is touched when it is partially outside of the frame of the parent scrollview, the scrollview scrolls up a little. For example, let's say we have a scroll view with a frame height of 200, but a contentSize height of 260 and we put a text field at position 220. Now I scroll up and position the textfield half inside of the scrollview's frame and let the other half get cut off. If I touch this textfield, I notice that the scrollview automatically scrolls up by a couple pixels before the keyboard comes up. This is problematic because I already have my own scrolling code, so when this happens, it ends up scrolling twice as far as I want it to. Is there any way to remove this default behavior?
It sounds like your scrollview is getting moved in response to the keyboard showing instead of the text field being tapped. Take a look at Apple's Managing the Keyboard documentation; it has a helpful section on scrollviews.
A similar question already has been answered here:
https://stackoverflow.com/a/5673026/550177
You can also try to reset the scrollview's contentOffset when the textfield becomes first responder. Implemement the text field delegate like this:
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[self.scrollView setContentOffset:_scrollView.contentOffset animated:NO];
}
This code removes that automatic animation when the textfield is selected. I've tested with iOS 6.1 in the simulator.

iPhone: UIScrollView not scrolling when adding item via IB

I'm trying to make a very simple scrolling page via IB. What I've got is a UIImageView at the top and 2 UIImageViews at the bottom, with a UITextView in the middle. I've disabled the scrolling in the UITextView as I won't the whole page to scroll up and down including the UIImageViews.
Can anyone tell me why the UIScrollView won't scroll up and down? All of the items above are subviews of UIScrollView via IB.
You can only scroll in a UIScrollView if the contentSize is larger than the frame. Have you set this?

IPhone App: UIScrollView scrolls to bottom when it loads

I have a detail view for a contact. The last field is a Textview that can be as short as 1 line and as long as 20. in the viewDidLoad method I use:
scrollView.contentSize = self.view.frame.size;
My problem is that when the data is displayed, the scroll view scrolls to the bottom on its own. Obviously I would like it to start at the top.
I used the Content offset with the bottom value set to about 300 to allow the view to even be able to scroll down far enough. I have tried to disable scrolling until the load is finished but then it just locks you at the bottom.
As you can probably tell I am new at iPhone Programming. Any ideas?
Set contentOffset to 0.
Then, go and read the docs. you're using the scroll view completely wrong.
UITextView is scrollable, so it's unclear why you're sticking it in a scroll view.

How to make modal view scrollable?

I have a modal view with a textview and a button. When the keyboard is displayed it covers up some of my UI elements. I'd like my modal to be scrollable so that it can be viewed while the keyboard is displayed. How can I do this?
I've had the same question, and i've played with it a bit,
setting a UIScrollView is not enough, as in the inspector
you should 1st. increase it Hight, then in the attributes, check the following checkboxes:
Scrolling enabled, Bounce Scroll, always bounce vertically.
Edited: Forgot the most inportant thing:
in the size inspector, set the Buttom field (under content) to the size you wish, (960 is twice the regular size)
Use a UIScrollView instead of an ordinary UIView. You can disable scrolling when you don't want the user to be able to with:
[theView setScrollEnabled:NO];