Mimic behaviour of UITableView section headers staying visible during scroll - iphone

When you have a sectioned, plain-style tableview on the iPhone, such as in the Contacts app, the section headers remain visible when you scroll past them until they are pushed offscreen by the next section header.
Does anyone know how to achieve something like this in an ordinary scrollview? I already have one scrollview nested in another to get horizontal paging with vertical smooth-scrolling, so I'm reluctant to add a third scrollview.
Cheers

Basically I did a bunch of maths in scrollViewDidScroll: and set the frame of the subview.
Edit:
Well my exact requirements were a bit different than the question I asked, I have a footer view as opposed to a header view. Basically in scrollViewDidScroll I have:
CGRect frame = self.footerView.frame;
frame.origin.y = MIN(self.bounds.size.height -
self.footerView.frame.size.height +
self.contentOffset.y,
self.contentSize.height);
self.footerView.frame = frame;
This ensures the footer view, which is a subview of the scroll view, is always visible at the bottom of the scroll view, and there is never a gap between the footer view and the bottom of the content view.

Related

scrolling not working for views inside tabbar application

I have created a tabBar application, it has two tabs one tableView with detail items and another simple UIView with a UILabel. I added scrollView to detailViewController and put all UI items under scrollView to get scrolling. I connected the scrollView using outlet to my detail view and set the following in detailViewController
[scrollView setScrollEnabled:YES];
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width,scrollView.frame.size.height);
However detail view is not scrolling, its screen is locked. why?
For a UIScrollView, you want the frame to be the size you want it to appear on the screen, and the content size to be the size it will be able to scroll through. So, for scrolling to work properly, you must have the content size set to larger than the view's size in one dimension or the other.

Make Area Page-able

How Can I make the green area of the screen shot of my app be able to scroll with the paging animation and page indicators?I would like for me to add more icon-buttons to it with keeping the header the same size.
First you need a scroll view and your view has to be inside of the scroll view.
Then you need to enable paging on the scroll view
[scrollView setPagingEnabled:YES];
If the value of this property is YES, the scroll view stops on multiples of the scroll view’s bounds when the user scrolls. The default value is NO.
If you want to have page indicators you need to use UIPageControlwhich you will have to manage yourself as far as I know. You could always check after scrolling (see UIScrollViewDelegate ) which page you are on based on the contentOffset property of the scroll view.

iPhone how to implement a "Wide" UITableViewCell?

I'd like to have a UITableView with cells wider than 320 points. The user should be able to scroll sideways to be able to view different parts of a UITableViewCell. Is this kind of behavior possible with a UITableView, or should I go and try to implement a tiling UIScrollView?
I tried wrapping a UITableView within a UIScrollView, and the results are terrible - they compete for the scroll gestures and most of the time the scroll view wins, preventing the table from being traversed vertically.
Any input is appreciated!
Thank you!
Update: I tried the proposed solution and it scrolls properly, but the tableview is still only 320 pixels wide. Is tableView's width linked to the window bounds ?
Wrapping the table view with the scroll view is the right way.
UIScrollView with
Show horizontal scrollers
scrolling enabled
autosize to full screen
Inside that, a UITableView
shows vertical scrollers
scrolling enabled
Then I set the table view's frame, with w, being the calculated width of the table view with all columns, whatever your width, and kTableScrollViewHeight being the fixed height of both the table view and the scroll view, in my case, for example 367 points (screen minus status, navbar and tabbar):
tv.frame = CGRectMake(0, 0, w, kTableScrollViewHeight);
and the scroll view's content size
scrollView.contentSize = CGSizeMake(w, kTableScrollViewHeight);
If you want the scroll-to-top behavior when the user taps the status bar, you might want to set
scrollView.scrollsToTop = NO;
because otherwise the scroll view will take away the tap from the table view.

IPhone App: UIScrollView scrolls to bottom when it loads

I have a detail view for a contact. The last field is a Textview that can be as short as 1 line and as long as 20. in the viewDidLoad method I use:
scrollView.contentSize = self.view.frame.size;
My problem is that when the data is displayed, the scroll view scrolls to the bottom on its own. Obviously I would like it to start at the top.
I used the Content offset with the bottom value set to about 300 to allow the view to even be able to scroll down far enough. I have tried to disable scrolling until the load is finished but then it just locks you at the bottom.
As you can probably tell I am new at iPhone Programming. Any ideas?
Set contentOffset to 0.
Then, go and read the docs. you're using the scroll view completely wrong.
UITextView is scrollable, so it's unclear why you're sticking it in a scroll view.

How do i anchor subviews of a UIScrollView like the URL bar in mobile safari?

I want to do something similar to how mobile safari keeps its URL bar anchored at the top of the screen while a page is loading unless you scroll past the top, in which case it scrolls down with the rest of the content.
I, however, want the opposite to happen; I want specific subviews to scroll off the screen if I scroll down, but if I scroll to the top I want the subviews to stay anchored at the top of the screen while the rest of the content continues to scroll down. I suppose I could do some trickery with the view hierarchy where the subviews change their superview when we scroll to the top, but I'm wondering if there are any other more elegant solutions to this.
Very late answer to my own question, but I figured i'd reveal how I was able to do this.
I subclassed UIScrollView and implemented the layoutSubviews method, which is called every time the scroll position changes. Here, all you need to do is identify which view you want to anchor and do something like this:
- (void) layoutSubviews {
[super layoutSubviews];
CGFloat x = 0.0f;
CGFloat y = MIN(self.contentOffset.y,0.0f);
anchorview.frame = CGRectMake(x,y,anchorview.frame.size.width,anchorview.frame.size.height);
}
If you want the anchored view to stay at the top if you scroll past the top (instead of remaining in the same position relative to the scrollview), then this will do just that, since the content offset's y coordinate will be less than zero when you scroll beyond the very top of the view.
UITableView section headers already do this in plain tables, you could leverage that behavior.