Controlling scroll viewer's scroll distance - windows-phone-7.1

I'm placing 20 textblocks in scroll viewer, but it scrolling upto 7? I also want to control the scroll distance in get scrolled whenever my application starts?

Probably, you set Height of ScrollViewer to Auto and it don't fit to screen. Set it to Parent Height. I hope it will work than.

Can you put up your code? Also make sure you have done these two things
1) Place it in a grid.row and set grid.rwo height to *
2) Do not place the scrollviewer in a stackpanel

Related

UISlider causing horizontal scrolling

I have a simple screen, with a slider and a label positioned next to each other horizontally. I have embedded these inside a UIScrollView (I set this to fill the screen and used 'Add missing constraints'), because I will need vertical scrolling later down the line. I don't however, want horizontal scrolling. I have seen numerous posts on here and other sources about people wanting to disable horizontal scrolling, however I'm not sure that's what I want to do, I think I need to restrict the UISlider from causing the horizontal scrolling; I think it is trying to take up more width than the screen. I have added what I think are the necessary horizontal constraints:
Leading space to container for the UISlider
Horizontal spacing to the UILabel, and
Trailing space to container for the UILabel
But this still causes horizontal scrolling, and the UISlider's are the cause, they are taking up more room than I want, as seen below:
I have tried disabling horizontal scrolling in the code using a few techniques, one being:
func scrollViewDidScroll(scrollView: UIScrollView) {
if scrollView.contentOffset.x>0 {
scrollView.contentOffset.x = 0
}
}
but this does not seem to stop the horizontal scrolling.
Can anyone offer any suggestions?
Thanks in advance.
My suggestion is to never use Add missing constraints. It never does what you really want.
Here's the problem. You are laying out your UI on a ViewController in the Storyboard that is square. Apple did this to remind you that you need to be flexible in your design, but it doesn't match the size of any device. When you Add missing constraints, it uses the absolute dimensions of that square to create the constraints which are certainly wrong.
In your specific case, it is giving the slider a width that is too wide, which is why the slider goes off the right side of your screen.
Here's the trick about scroll views. If the contents inside of a scroll view are wider than the scroll view itself, then that content will scroll. The same applies vertically: if the contents inside of a scroll view are taller than the scroll view, then the contents will scroll.
In order to design this to work on all phones, you need to make sure that the contents of the scroll view are laid out correctly for each phone size. Which certainly means you don't want to use specific widths for both the label and the slider because you'll end up with the wrong width for some device, if not all of them.
The best way to do this is to:
Drag out the scroll view and add it to your ViewController. Add constraints to make sure it is properly sized on all phones, such as attaching it on all sides to its superview with a fixed distance.
Drag out a new UIView and drop it on the scroll view. Drag its edges until it exactly matches the size of the scroll view. This will be your content view. Pin all four edges of this content view to the scroll view with offsets of 0.
Here's a tricky bit. Even though you've pinned the content view to the scroll view, its size of free to grow because that is what allows it to be bigger than the scroll view itself and allow there to be content to scroll over. To keep your scroll view from scrolling horizontally, you need to make sure the content view has the same width as the scroll view on all devices. To do that, find the scroll view and the content view in the Document Outline to the left of the Storyboard. Control-drag from the content view to the scroll view and select Equal Widths from the pop-up.
You still haven't told your content view how tall it should be. For now, give it an explicit height constraint of 1000. That will be enough to scroll.
Now, add your label and slider to the content view. In addition to constraining them to each other and to the edges of the content view, you will need to give your label a width constraint. Then Auto Layout will have all of the information it needs to compute the width of your slider. Auto Layout knows how wide the content view is (which will be different on different devices), it knows how wide your label is, and how far everything is from everything else, so it will just stretch the slider to fill in the rest.
If you do all of this, you will have a UI that is properly sized for all devices in all orientations that scrolls vertically.
Just embed all view in your UIScrollView in a UIView, give it the required constraints then the slider and label will stay.
That worked for me just now.
UIScrollView is special when you want use AutoLayout with it, subviews can not be added directly, it needs a container view to constraint the contentSize of UIScrollView, Auto Layout Guide:Working with Scroll Views explains the detail reason, and you can find many solutions to solve UIScrollView's auto layout on Google, Such as this answer.
To be honest, it's confused and complicated to understand UIScrollView's auto layout, but if you overcome this, others auto layout question is easy to resolve.

Simple scroll view constraints change?

I created a scroll view in Xcode that works awesome because of this video.
https://www.youtube.com/watch?v=3PIm8-lKAYw
When I was messing around after I made it I found out that if I clicked on the scroll view and went to Show the Size Inspector or the fifth button on the right hand side of the screen I had the option to make a constraint called Top Space change in value that caused the scroll view to become bigger and smaller. I decided to see if I could find a way to change the constraint programmatically by simply using dot notation and the equaling it to an int value that I wanted.
So what I'm trying to figure out is there a simple way to change these constraints values programmatically that change the scroll view constraints values?
Without actually following that tutorial (and there being no code in your question) I'm going to make a few assumptions.
Yes, it is possible to change the scroll view's content size by manipulating constraints in your code. If you are creating the constraints in a xib or storyboard, you will need to make sure they are hooked up to IBOutlets so that you can access them in your code.
If you have 2 views arranged vertically that affect the vertical content size of your scroll view, increasing the space between these views would also increase the vertical size of your scrollview's content size. The following would increase the space between 2 views by 20 (assuming a multiplier of 1) and subsequently increase the scrollview's vertical space by the same amount.
// This is a vertical space constraint created in your xib or storyboard between 2 views that drive the content size of your scrollview
someVerticalSpaceConstraint.constant += 20;

UIStepper moves out from screen, why?

I have an UIStepper in tableView. It is in a container view, but that one has correctly set up, with constraints etc.
Any idea what is the problem?
You constraint for First UILable may having Expandable Width, which leads to move next three controller to move aside, eventually next controls moves its position by frame.x increasing.
You can stop first UILable to increase width by deleting Adjust width constraint. Alternate to change width, you can size down the font size and increase number of lines.
HTH, Enjoy Coding !!
I forget to add width constrain to UIStepper. It is not strait forward that it has a 94px width, it has to be specified.

How to resize storyboard? ios

I have more than 10 static table view cells in my app. How can I drag and drop it to storyboard? I can see only 7 of them, Its scrolling on simulator^ but not in storyboard
tables dont scroll on storyboards or in the .xib files ,u just have to set the scrolling to yes and then u see it scrolling in simulator or devices
This problem is very common in UIScrollView when Scroll content increase view Size.
There is no inbuilt solution like increase size of ViewController.
But we can have intermediate solution which can help us. Do following.
Increase size of UIScrollView or UITableView such that it cover all content. something like 1000 or 1500.
set Y to some minus value (like -100 or -300) so your control goes upside and you can see content at down side.
You have to set your Y according to which content you want to see.
Don't forget to change height back to original value after you finish work.

Setting correct sizes when using UIScrollView and setContentSize

I simply just want to have more controls than I can fit on the normal iPhone screen. Take for example viewing someone's contact information in the Contacts app.
It appears that I should use a UIScrollView to implement this.
Lets say I need about 800 pixels for this. So in my NIB, I set the View of the ScrollView to have a height of 800. I then add my controls under the Scroll View.
I make my connection, and then in the viewDidLoad, I do the usual:
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 800)];
If I build and run at this state, it wont scroll. So looking around online, people say that you have to set this to be larger than the UIScrollView.
I can't seem to find information on how to actually calculate what that 800 should be in the setContentSize. Is it just guessing until it looks right? If I set it to 801, I never see everything at the bottom of my Scroll View, and if I set it to 1000 I can see the bottom, but it doesn't really end at the bottom.
I just want that if the user scrolls down, it ends at the bottom correctly.
How is this calculated? Or am I missing something? This seems like a rather common use but haven't found code examples that simulate this simple example.
Scrollview provides a perspective onto a bigger canvas by showing a smaller region but allowing you to pan across the canvas. Now when you set the scrollview's frame size and the content size to be same, the purpose is defeated. Hence no scrolling.
When you define the scroll view's frame to be 320x800 on a window/view that is of size 320x480, part of the view is clipped off. It is not visible but its there. You content is there too. What you need to do is to set the scroll view to match the window's size i.e. 320x480. Now you will have scrolling as the perspective is smaller than the canvas.

Resources