ScrollView start scroll only second time that the view appear - iphone

I've a problem with my view in iOS7 with autolayout.
This is my structure:
The UITextView content is dynamic so I fit his contentSize dynamically in the viewDidLoad.
In my viewDidAppear I try to fit the contentSize of the MainScroll and the mother view calculated by the sum of UIScrollView height (the little one), Pager height and UITextView height. I logged this height and it returned the correct size: 1300px but the view doesn't scroll.
If I change tab and return here the scroll start to scroll, I've tried to put every piece of code in the viewDidLoad but it doesn't work.
Can you help me?
Thanks and sorry for bad English.

Try selecting it and then selecting "reset to suggested constraints" in the storyboard. :).

Related

What am I doing wrong with this Scrollview?

I am attempting to set up a scroll view and every video I watch they say the same things:
•Make scrollview in VC
•Make it bound to all margins (0,0,0,0)
•Embed a content view inside of Scrollview
•Content view margins are (0,0,0,0)
•Set Equal heights & width from content view to superview
•set priority of height to 250
I have done this time and time again and cannot figure out why it still isn't working. Can someone please double check these screenshots?
Try adding some subviews into your content view and make sure to have a complete set of vertical constraints from top to bottom.
If you go in the Size inspector under the "Scroll View" Section you can find the "Content Layout Guides" tick, disable and the errors will disappear
If you Set All the constraints to ScrollView and want to set its contents in code .. it remains complaining about its constraints because they remain ambiguous .. so to remove error from story board
what you do is set Ambiguity to never verify and error will go away .... hope it will help
Looks like you do not have anything bound to your Content Layout Guide.
So basically you have two guides in Scroll View: Frame and Content.
Frame Layout Guide provides you the ability to bind to your UIScrollView's frame. E.g. equal width between your Content view and Scroll View itself.
The most useful here is Content Layout Guide. Basically it helps to determine the scrollable content size of your UIScrollView's contents.
So in your case you have to have a Content view inside your Scroll View that has equal width with Frame Layout Guide and have its edges pinned to Content Layout Guide. Like so:
Oh, and do not forget to have your Content view have a determined height so your scroll view will calculate the size of its scrollable contents.

ScrollView in iPhone interfacebuilder

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.

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.

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!!

UITextView inside UIScrollView scroll problem

I'm experiencing something considered a bug in my situation. Probably this is not a bug but a feature ;).
Here's my case:
I load a UIScrollView with my content. A part of my content is loaded asynchrone after the view is already loaded. This works great and without issue.
Some of these controls however are UITextView controls. Once I set the content (text property) of these controls after the viewDidLoad my UIScrollView scrolls down to the last UITextView that was set. I want to prevent this and want the UIScrollView to maintain it's top scrolled position.
In summary:
If I set the Text property in the viewDidLoad method no scroll occurs. If I set the Text property on the UITextView after the viewDidLoad method (because I load the data asynchronous) the UIScrollView will scroll to the last UITextView that was set. I want to prevent this scroll.
How do I achieve this ? I have a feeling this is just a property which is set wrong but I can't seem to find it.
Thanks in advance.
EDIT:
I've tried setting the "scrollEnabled" property to NO before setting the values and to YES after but this didn't have any effect. The ScrollView will still scroll when the text property of the UITextView is set.
I Fixed the issue with a work-around:
I set the scroll view content size to something small, like 320 x 300 or whatever the height of the scrollview frame is, then did my work, then put the content size back to normal.
This prevents the scrolling while the data is loaded and enables it as soon as the loading is finished.
This would not change the scrolling problem but maybe make it "hidden" for the user:
yourTextView.text = #"Eat more bananas!";
yourScrollView.contentOffset = CGPointMake(0.0, 0.0);
Some snippets of your code would help to face the problem more specific.
EDIT:
Or try to add the UITextViews to a UIView, then add the UIView to the UIScrollView. Make sure that the UIScrollView's contentSize is the same as the Size of the UIView.
This worked for me too :p but i had to set the height to something less then 300 (in my case i just used 10).
Basically the idea is to make the text view not part of the visible area of the UIScrollView wile you are changing the text of th UITextView.