ScrollView in iPhone interfacebuilder - iphone

I have put 14 items in scroll view but it gets stuck after 6 items. I have not put any code, just did all from interface builder (items are arranged vertically). I can see the items below but it jumps to 6 items when I release the touch. It is not that the scroll view is not working, it is just not showing as much I want it to show.
Has any-body got any idea what is happening? any help is appreciated.

You should set the content size of your scrollview.
e.g.
[scrollview setContentSize:CGSizeMake(scrollview.contentSize.width, heigth)];
Where set height that contains all your sub controls in scrollview.

Scrollview content size is not set properly. Use setContentSize: to set the content size of the scrollview
You added the content into scrollview so now you have to make scroll know to what size it shoul scroll and show the content
Do
Set an outlet and then add this code in viewDidLoad
[scrollview setContentSize:CGSizeMake(width, height)];
From Docs
contentSize
The size of the content view.
#property(nonatomic) CGSize contentSize
Discussion
The unit of size is points. The default size is CGSizeZero.
Here is a nice tutorial since you are a beginner .

may be its too late, but here is how i solved it:
put the items in a UIView and stretch that view as much as it need to be stretched.
put that UIView in the scrollview.
put a scroll view in the main uiview, the height and width will be similar to uiview.

Related

UIScrollView Customize size(not getting)

I'm having an UIScrollView attached to a UIView using interfacebuilder, to that UIScrollView I added subviews, UILabels, UIButtons etc.
In my .m file i have given like this
[testscroll setScrollEnabled:YES];
[self.testscroll setContentSize:CGSizeMake(320, 1560)];
I can visible UIScrollView but it is up to the limit(not for the totalview) I increased height in setContentSize but there is no use
I think this is the simple question but am not getting it please help me.
Check the height of the scroll at IB.
If the view height and scroll content height are same then the scroll would not scroll.
Check the scroll height at IB and reduce accordingly
Check out these scenario this may help,
1>first check you bind scrollview correctly.
2>if you make property of scrollview then only use self. testscroll
3>set the content size in ViewdidLoad

UIScrollview only scrolls when empty

I updated xcode to 4.5 but now when I make à UIScrollview it stops scrolling as soon I place something in the scroll like à label or button, when I remove them the scrolls works again
someone knows the fix?
Code
My ScrollView is 320 by 430 and in my viewdidload I use:
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 481)];
edit
I just discovered that in landscape mode it does scroll so maybe I am setting my content size wrong? :S
edit#2
It works now if I make a text view in the scrollview and make the text larger then the screen, but When I place a button into it the button doesnt scroll along ..
Extra
I made a video showing What I do hope someone can tell me what im doing wrong
http://www.youtube.com/watch?v=rzYTWLiIC8g&feature=youtu.be
"Use Autolayout" was on it has to be off and it will be fixed thanks for all your support.
You don't have enough content for scrolling.
Please add more content text. Then only it scroll.
Set the contentSize of your scroll view to the size of the content, eg. if you have 10 rows of buttons, each row's height let's say 40px, and padding 5px, the height (height if you are putting the content vertically, width if horizontally) of the contentSize of the scroll view is: 10*45.0f+5.0f. If this doesn't help, then show us your code.

scrollview and textview problem with scrolling iphone

i have a view, then in the view i have a scrollview and then in the scrollview i have a bunch of different objects. These objects aren't bigger than the scrollview's size, so i put a textView with a lot of text in the scrollview to see if it works but it is not scrolling. I deactivated the textview's scroll function. Does the scrollview knows the size of my textview? The textview's text is being set programmatically. Here's my view hierarchy:
Thanks in advance.
If you set the text programatically (and the size of the textview I assume since you don't scroll in it) you will have to set the contentSize of the scrollview after that. It doesn't automagically know when one of its elements grow.
And also set
scrollView.scrollEnabled = YES;

UIScrollView won't scroll!

In IB I have my UIView. Then I have a sub-UIView with a UIScrollView as a sub view. Then the UIScrollView has a sub-UIImageView. The UIScrollView and UIImageView are the same size. They're much bigger than the UIView of which they are subviews. I assumed this would make scrolling work. It doesn't. Is some sort of code required for scroll views to work?
You need to set UIScrollView.contentSize to match the total scrollable size, which is your subview frame size in this case.
As mentioned in the accepted answer, you must set the UIScrollView's contentSize property.
This can be done in Interface Builder.
Select the scroll view
Select the 'identity inspect' in Utilities pane on the right
Under 'User Defined Runtime Attributes' click the '+' button
Set the 'Key Path' value to 'contentSize'
Set the 'Type' value to 'Size'
Set the 'Value' value to '{width, height}' (eg: '{320, 600}')
Build and run and your scroll view will scroll.
The content inset does not affect scrolling. See What's the UIScrollView contentInset property for?
To scroll, you have to make the scrollview's frame smaller than its content, the contained image or view.
This might be obvious to most, but I spent ages wondering why my UIScrollView wouldn't scroll so I'm posting what was stopping me in case it helps anyone else:
The UIScrollView has to be of the dimensions of the visible area in which you wish it to be presented and not the size of it's contents.
Ridiculous on my behalf I know, but just in case it helps someone.
I placed all the content of my scrollview in IB. (buttons, labels, text fields, etc). The full size is 500 tall.
I then resized it to 436 tall in IB.
Then in code, I put this is viewDidLoad:
optionsScrollView.contentSize = CGSizeMake(320,500);
So that leaves 64 pixels that I can scroll. It works perfectly.
I also placed "UIScrollViewDelegate" in the <> braces of #interface for my .h file and tied the delegate outlet of the scrollview to File's owner in IB.
I could solve the scrolling problem with the following answer:
https://stackoverflow.com/a/39945124/5056173
By me the trick was:
You now need to set the height of the content UIView. You can then either specify the height of the content view (blech) or use the
height of the controls contained within by making sure the bottom
control is constrained to the bottom of the content view.
I have set the height and width of the view inside the scrollView with center vertical and horizontal alignment and that was the reason, why it did not work!
After deleting this constraints, I need to add equal width (scrollView and the view inside the scrollView) AND I set the height of the view inside the scrollView directly with the content. Which means: The last element in the view must have a bottom constraint to the view!!
The other important thing that I don't see mentioned here is that UIScrollView does not play nicely with AutoLayout. If it seems like you've done everything correctly, check if your ViewController has autolayout turned on and, if so, turn it off.
(Every time you scroll, the views are re-laid-out. Gak!)
So:
Make sure scrollview's contentSize is bigger than its frame.size
Make sure AutoLayout for the ViewController is turned off.
more, did you enable scrolling?
look at the property
#property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled
Make sure 3 things,
checking scrollView frame & contentView frame, u may find the answer
scrollView.isScrollEnabled = true
contentView of scrollView height didn't constraint with scroll view height
UIScrollView won't scroll!
reason: contentSize is same as (sub) view
should: contentSize is large than (sub) view
-> UIScrollView can scroll
how set UIScrollView contentSize?
two method:
in code
- (void)viewDidLoad {
[super viewDidLoad];
。。。
//[(UIScrollView *)self.view setContentSize:CGSizeMake(375, 1000)];
CGSize curScreenSize = UIScreen.mainScreen.bounds.size;
CGFloat scrollWidth = curScreenSize.width;
CGFloat scrollHeight = curScreenSize.height * 2;
[(UIScrollView *)self.view setContentSize:CGSizeMake(scrollWidth, scrollHeight)];
in UI (Storyboard)
Storyboard-》Identity Inspector-》User Defined Runtime Attributes-》 add new attribute:
contentSize
Type:Size
Value:{375, 1000}
Scroll view works with this:
Frame
then
contentSize
views or objects etc...
If your frame is set to your content size then it won't scroll.
So set your frame ( in IB right panel -> second last tab 'Size Inspector") to the length of your app ( in my case it is 367 as i have a navbar and a tab bar) then programatically set the contentSize to - yup you guessed it ... more than your frame so it can scroll.
Happy days!!

iPhone : TabBar overlaps above UIScrollView

I have created an iPhone UI programmatically but I just can't figure out how to fit a view so that it doesn't get overlapped by the TabBar. Here's the ownership hierarchy:
- AppDelegate
UITabBarController
UINavigationController x
UITableViewController
UIViewController (with XIB)
UIScrollViewController (in the same XIB as parent)
The problem is that my TabBar hides a part of my UIScrollView (and my tableviews as well, but that's not important). I tried manipulating the scrollview content size and the view frame size but with no luck.
So far the best I could do was to add a 60px padding on the scrollview's content size like this:
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height+60)];
Thanks for your help!
Sounds like you may have to make sure your scrollView's frame is set properly first. The contentSize will determine the dimensions of the content of the scrollView. In other words how far you can scroll in each direction. Take a look at the scrollView in your nib and make sure the frame is the right size you need to fill.