UIScrollView strange ScrollIndicator as compare to UITableView - iphone

I am using a UIScrollView and while scrolling it I noticed the ScrollIndicator was shrinking based on my scroll inset. But this is not the case with UITableView.
I have tried doing [scrView setBounces:NO], but that doesn't make it more user-friendly and also it hinders the scroll movement.
Is there any way to make UIScrollView scrollIndicator same as UITableView scrollIndicator?
Thanks for any help!

For a UITableViewController you can switch Bounces off, which means that tableView can not be elastically pulled upwards and then it bounces back. This also means that the scrollbar will not shrink.
You can switch it off using setBounces:
[self.tableView setBounces:NO];
You can do the same in a UIScrollView. See documentation: http://developer.apple.com/library/ios/documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html#//apple_ref/occ/instp/UIScrollView/bounces

Related

TableViewController for scrolling horizontally

I need a tableviewcontroller that scrolls horizontally instead of vertically.
Is there one available? Because I have to use a scrollview now which might get memory hungry after a while!
Try implementing this in a UIScrollView, and reuse your cells.
We have used UIScrollView for each cell and we scroll them together when either of them is scrolled. Our app has loads of data in the tableview and we are doing fine. You can try this approach.
I would make my own horizontal table view that inherits from UIScrollView. Implementing your own dequeueReusableCellWithIdentifier: isn't very hard.
What about using the standard one, then rotating the contents of each of the cells by 90 degrees?
It would have the same effect for the end user.
You could rotate your UITableView 90 degrees.
Yes most definitely this is possible. It is possible to do so.
STEP-1:
You just have to put your tableView under a UIScrollView in your Interface Builder or by coding as per your liking (i.e. as a subview of UIScrollView)
Using coding you can do that as
[scroll addSubView:tableView];
STEP-2:
Then you need to make the width of tableView more than size of the View. So tableView Width is more than 320 (say it is 600)
[tableView setFrame:CGRectMake(0,0,600,460)];
STEP-3:
Then you just have to set the UIScrollView's ContentSize as CGSize(600,460)
like
scroll.ContentSize = CGSize(600,420);
Now just build and run and You are done.
Hope this helps you. :)
If you have any doubts then please leave a comment here.
Remember: In any case you need to re-use your tableViewCells as otherwise it would leak memory.
EDIT:
You can refer the basic logic here for rotating your tableView by 90 degrees, though it is about UIImageView rotation by 90 degrees but I think this will help you.
How to programmatically rotate image by 90 Degrees in iPhone?

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?

Prevent subview from scrolling in a UIScrollView

I have a UIScrollView subclass with a certain subview I'd like to prevent from scrolling (while all the other subviews scroll as normal).
The closest example to this I can think of is UITableView's "index strip" on the right side (look in the Contacts app to see an example). I am guessing this is a subview of the table (scrollview) but it does not move as the user scrolls.
I can't seem to make my subview stay put! How can I accomplish this?
The trick is to adjust the frame of the "non-scrollable" subview inside -layoutSubviews.
Add the view that you want not to move as a sibling view of the scroll view on top of the scroll view instead of as a subview.
You can set it's property called userInteractionEnabled to NO

UIScrollView not showing scroll indicator

I have a UIScrollView which I create and size dynamically using...
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width , length);
I then add subviews to the UIScrollView.
I do have scrollView.showsVerticalScrollIndicator = YES;
When scrolling the scroll indicator never appears.
Even if I call [scrollView flashScrollIndicators] nothing happens.
Ideas?
Had the same problem and couldn't find the cause. The last answer gave the final hint: whenever I added new subviews I first removed all existing subviews from the scrollview (and apparently also the scroll indicators).
After checking in my loop, if the subview really was of the kind I wanted to be removed the scroll indicators showed up:
for (NSObject * subview in [[[scrollView subviews] copy] autorelease]) {
if ([subview isKindOfClass:[MySubView class]]) {
[(MySubView*)subview removeFromSuperview];
}
}
Update: changed code to Nikolai's suggestion
When I've dealt with this before, in my implementation of a grid, I would occasionally get some cells over the top of the scroll indicator. To fix this I am now inserting subviews at index 0 rather than adding them, which adds them to the top. So try something like this:
[scrollview insertSubview:subview atIndex:0];
For me, the horizontal indicator had mysteriously disappeared in my app on iOS 7. Later found out that for some strange reason, I had to enable both Shows Horizontal Indicator and Shows Vertical Indicator to make the horizontal one show up. If I set it to not show the vertical indicator, it would also not show horizontal indicator.
I fix this by adding this code after add new subview:
self.showsVerticalScrollIndicator = NO;
self.showsVerticalScrollIndicator = YES;
It will also happen (at least in the case of a UITableView) if the contentSize is too small for the table view to scroll. If you have enabled bouncing, then the tableview does not actually scroll and does not display the indicators therefore. Try fitting more content inside.
It can happen also if the parent of the scrollview is smaller horizontally than the scroll view itself :
The scroll bar is stuck to the right side of the ScrollView / TableView and this right side is not visible due to the parent bounds ( with a clipToBounds hidding it for instance).
I've seen this issue so I share it in case it can help.
Just check the width of your ScrollView's frame not to be bigger than the width of its parent view frame.
Two conditions,
If you are using a storyboard
If you are using a UITableView inside a UIViewController
Then, you should check your indicator insets are set to 0 (or any other number that is relevant to your autolayout):
Noticed this when the UIScrollView was a 48 px tall horizontal band, scrollable horizontally. Maybe Cocoa decides the area is too small for a scroll indicator...

UIScrollView not scrolling when set to a tableView's tableHeaderView

I'm having difficulty scrolling a UIScrollView instance in my UITableView when I set it as a tableHeaderView.
It still responds to touch events it appears, but doesn't wish to scroll horizontally. I've tried explicitly setting to setUserInteractionEnabled:YES without much luck.
Is there something in particular I need to do to get scrolling working when this is set as a tableHeaderView?
Thanks.
You probably need to check your scrollView.contentSize, ensure scrollView.contentSize.width > bound width.
This embeds a UIScrollView inside a UIScrollView (since UITableView is a UIScrollView). You probably want to set the tableview's canCancelContentTouches to NO so it doesn't cancel your UIScrollView's touches. That may create some problems if your UITableView needs to scroll vertically.
If that is your issue, subclass UITableView to overload touchesShouldCancelInContentView: so that this does not return YES for horizontal drags (or perhaps for touches in the header).