problems with scrollview, not scrolling full length - ios

I have a scroll view, added in the IB, and also I added a lot of objects/controls to it on IB itself. Some of them are added to the scrollview but they are out of its bounds.
Back in the class, I'm setting its content size like this
self.scrollView.delegate = self;
self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height + 500);
The scrolling length I observe is not that much. I just observe like 500 px (while the height I set in the content size is around 900 px).
Please tell me what I'm doing wrong.

I use the IB to set the scroll view and the inner controls and I let the scroll view to be longer than the view area it self as why do you need to set it inside the code unless you draw the inner controls dynamically at the runtime ...I hope it is useful

Related

runtime expansion of uitableview footerview using autolayout

I have a UIView that is a footerview of a uitableview. At run time, the user enters text into a uitextview within the footerview that should adjust to the size of the text content with a height constraint in autolayout.
All other objects in the view (labels, imageviews) have appropriate constraints to accommodate the expansion of the textview.
HOWEVER the height of the overall footerview will not change size, and it is impossible to use autolayout on the tableview footerview height.
Does anyone have a solution? Thanks
Haven't found an actual, elegant, solution yet, but I've postponed fixing this by using a workaround:
Setting the frame of the view used as a footer to be as large as you might possible need. In my case this meant giving it about 60px of spare vertical room. Since it's the footer and there's nothing below it to reposition the user won't be affected by the workaround.
The contents of the footer view are pinned to the top and have enough space to expand when needed.
For the record: my view is loaded from a nib file.
Although in theory the size one gives to the top level view in interface builder is just for design-time and the runtime size should be calculated based on constraints and the resulting intrinsic size, for this specific case I found the height stays the same as it was in IB.
We can change the height of the footer view run time by the following code:
func methodToChangeTableViewFooterHeight()
{
var footerView:UIView = self._tableView.tableFooterView! as UIView
var frame:CGRect = footerView.frame
frame.size.height = self.heightCollectionCS.constant + 10
footerView.frame = frame
self._tableView.tableFooterView! = footerView
}
Here , self.heightCollectionCS.constant is the height constraint for our Collection View.
We can use text content height on that place.
You may try to set again the footer view each time you footer height changes, to inform the table it should change the footer height. Or use inset. From within the footer view:
SetNeedsLayout()
LayoutIfNeeded()
ownertable.TableFooterView = this
Sorry about that, misread that question long ago. You can access the footer directly through the tableview's property tableFooterView.
What you could do is create your default footer in a xib or in your viewDidLoad:. Once you need to increase the size of the footer, you can pull out the UIView from that property and edit its frame if necessary to make it larger.
So make sure the tableFooterView gets assigned a UIView because it is nil by default. To just make the height taller, you can use self.tableView.tableFooterView.frame = CGRectMake(whatever rect you need);

Can't add a UIScrollView to a part of the view

Inside a UIViewController, I need to have the bottom half scrollable. So I added a UIScrollView and positioned it halfway down the view's height. And in the viewDidAppear method, I have put the below two code lines to make it scrollable.
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.scrollView.frame.size.height);
self.scrollView.frame = self.view.frame;
This way works if the scroll view fills the entire view, I've tested. But this method didn't work for my need. The scroll view would automatically move up and take up the entire screen. I assumed it was the second line of code which causes this.
So I removed the scroll view, added two UIViews to the view controller. To the bottom view, I added the UIScrollView. And in the viewDidAppear method, I have put the same two code lines changing the second line to refer the frame of the UIView that contains the scroll view..
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.scrollView.frame.size.height);
self.scrollView.frame = self.containerView.frame;
But it wouldn't scroll either.
Can anyone please tell me how to do this correctly?
Thank you.
Dude, you keep setting the frame of the scrollView to something completely different from what you're actually trying to achieve.
If all you want to do is setup your scroll view so that it only occupies half the space then why dont you just set the frame so that the height only covers the portion of the screen that you want it to cover; and then set the x & y coordinates so that you draw the scroll view from the right position.
Do something like this:
//Shortcut to view's frame.
CGRect viewsFrame = self.view.frame;
/**
CGRectMake takes 4 parameters: x, y, width, height
x: is set to 0 since you want the scrollview to start from the left with no margin
y: you want the y position to start half way, so we grab the view's height and divide by 2
width: you want your scrollview to span from left to right, so simply grab the view's width
height: you want your scrollview's height to be half of your screen height, so get view's height and divide by 2.
*/
CGRect frameForSV = CGRectMake(0, viewsFrame.size.height/2, viewsFrame.size.width, viewsFrame.size.height/2);
UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:frameForSV];
[self.view addSubview:myScrollView];
Then set your content size not based on an ansolute value, its best to have it based on the size of the content that's actually inside your scrollview so that your scrollview always scrolls to cover all your content inside it.
Also, remember that your scrollview will only scroll if the contentsize is greater than the scrollview's frame
UPDATE 1 after reading your comment in this post simply comment out any code in your viewController.m file related to your scrollview since youre setting up everything in interface builder.
This is the result:

UIScrollView ContentSize Limited to the Size of the UIScollView

I have set the contentSize of the UIScrollView as follows:
self.scrollView.contentSize = CGSizeMake(320,800);
But as you can see in the image below it still displays one last line under the UITabbar. Why?
I am using iOS 7.
The scrollView's contentSize refers to the size of the content that can be scrolled through. For example you could have a contentSize height of 2000 px, because you have 2000 px worth of content to scroll through.
Your contentSize is not the problem; you indeed want it to be 800 (I'm assuming that's the height of all your text and graphics, not including the tab bar at the bottom.) What you want to change is the actual size of the scrollView object itself. Then the scrollView will be the correct height (something like scrnHeight - tabBarHeight) but the contentSize will still reflect the size of the content (the stuff inside the scrollView).
[self.scrollView setFrame:CGRectMake(self.scrollView.frame.origin.x,
self.scrollView.frame.origin.Y, 320, scrnHeight - tabBarHeight)];
self.scrollView.contentSize = CGSizeMake(320, 800);
And then you should be all set. Now it's possible that 800 isn't actually the number you want; the number you want is the exact height from the top of the scrollview to the very botom of that text at the bottom. But this is the idea :)

Scrolling Issues in IOS

Scroll view did not set content size if I set it using a dynamic variable i.e.
scrollView.contentSize=CGSizeMake(320,scrollView.frame.origin.y+120);
the scroll view size remains same after calling above method.
But if I set it using a number (integer or float) it gets changed but it gives a very strange effect on scrolling. Picture of effect is attached.
scrollView.contentSize=CGSizeMake(320,1000);
This is not allowing me to post image anyways a strange effect appears.
How I can get rid of it?
Please tell Whats going wrong or what I am missing?
Now i have got rannking upto 11 the image for effect is given here.
Before Increasing Content Size:
After Increasing Content Size on Scrolling follwing effect appears:
Select the Scroll View and view its Size Inspector window. Observe that its size is 320 , 713 points (in my case). If you do not see the same
size as what I have, this is a good time to adjust the size so that it is the same as mine. You will
need to use this value in your code
(void)viewDidLoad {
scrollView.frame = CGRectMake(0, 0, 320, 460);
[scrollView setContentSize:CGSizeMake(320, 713)];
[super viewDidLoad];
}
i think you should use frame.height to achieve your goal
the content size must be greater then frame size of scroll view for scroll
and you are using y origin of scroll view so may be that's the problem.
scrollView.contentSize=CGSizeMake(320,scrollView.frame.size.height+120);
In this line:
scrollView.contentSize=CGSizeMake(320,scrollView.frame.origin.y+120);
You are setting the scroll view's contentsize's height to scrollView.frame.origin.y+120.
Means, if your scroll view's frame is x=40, y=40, width = 500, height = 500. Then the scrollView.frame.origin.y+120 will be equal to 40 + 120 = 160. Which is less than your scrollview's height. So your scroll view won't scroll to up or down.
In the second line:
scrollView.contentSize=CGSizeMake(320,1000);
You are scroll view's content size's height to 1000. That is greater than the scroll view's height so it'll scroll to up and down.
Finally.......
The issue was scroll view increases width of scroll view indicator which shows on the screnn while scrolling. You have two options to get rid of this.
Disable vertical or horizotnal indicators which one causing problem, but this may cause some problem with scroll view content size in my case it caused a problem last cell was not being viewed.
2.Let it appear but make it out of screen by the following code snippet.
[myScrollView setScrollIndicatorInsets:UIEdgeInsetsMake(0.0, 0.0, 0, 320.0)];
this is working perfectly but scroll indicator is gone out of screen.

UIScrollView how to set ContentInset and ScrollerInset

im not able to configure my UIScrollView.
The image above shows my view. The orange box is my UIScrollView and the blue boxes (plus the orange box) is the view that i want to scroll.
The View is 520px with and the UIScollView (as usual) 320px.
How have I to set the ContentInset and ScollerInset?
Since the heights of the scroll view and its content match, and because it does not appear from your picture that you would like to add an empty space to the content, you should keep the contentInset set to zero (as it is by default). If you would like the content's middle to be visible through the scroll view, set content offset to (520-320)/2 = 100, like this:
[scrollView setContentOffset:CGPointMake(100, 0) animated:YES];
// If you do not want to see the view scroll, change this ^^^ to NO
I'm not sure exactly what your question is, but I'm guessing your scrollview is not scrolling as expected.
You need to set the contentSize property to tell the scrollview that there is more content than just the viewable area (e.g. myScrollView.contentSize = CGSizeMake(520.0, 100.0);)
If you want to start with the content centred as per your diagram, you can to set the contentOffset property. (e.g. myScrollView.contentOffset = CGPointMake((myScrollView.contentSize.width - myScrollView.frame.size.width) / 2, 0.0);)

Resources