Gain control over scroll view - iphone

I have a scroll view which contains several objects like text fields,labels,switch etc..Now as we are aware that a table view by default provides control for user to scroll and stop where ever he/she wishes to.Like wise I want to achieve the same control for scroll view to stop any where at any point of the view.But my scroll view is not behaving properly,It is not stopping when scrolling is in progress.In other words scroll view is lacking smooth behavior.Instead it is scrolling to the extreme end and showing the 2nd half of view or it is appearing as if it is scrolling and its making the view unchanged i.e. to the start point and showing the view as it is.May be this description might sound a little bit confusing,but in one word I want my scroll view during scrolling,to stop at any object in the view,just as in the case of a table view,so that it is user-friendly.
I have set the frame and content off set to the scroll view in view Will Appear method as follows:
-(void)viewWillAppear:(BOOL)animated
{
scrollView.frame = CGRectMake(0, 0, 320, 460);
[scrollView setContentSize:(CGSizeMake(320, 815))];
}
Note : I have a tab bar controller on the bottom of view,to navigate between controllers.
I have just gone through the UIScrollView as well as delegate class references.I have come across paging,scroll view will begin dragging,scroll to row at index path etc.. methods.Out of these what method I need to implement and what is the logic I need to write.
Want some valuable suggestions.
Thanks all in advance :)

OOps....its my mistake :(
We need to disable paging enabled property or set to no if it is set to true or yes either in IB or in our code snippet....thanks :)

Related

Multiple CollectionViews inside a Scrollview

I am trying to create a horizontal scroller which starts with a collectionview (group1), when scrolling reaches the end of group1, I need another collectionview to page into view, and so on.
I am new to this and I can't quite figure out how to solve it.
I have no problem creating a scrollview which adds three different views, however since the contentsize is set like so: self.scrollView.contentSize = CGSizeMake(320*[controllers count], 460);
A specific view only displays as many cells as it can fit, leaving the rest behind the next view as you scroll.So to clarify this, I need to scroll inside one collectionview before the scrollview pops me over to another collectionview.
Any help or pointers in the right direction would be highly appreciated.

iOS: Add UIView to UITableView

I'm trying to add a UIView on top over the UITableView to mimic the iPhone Facebook style menu. I have it working fine by making the controller a UIViewController then adding a tableview however I am unable to make the menu a static menu unless the controller is a UITableView.
Is it possible to add a view ontop of a tableview and only make the tableview in the background scrollable without the view in the foreground scrolling?
Here is what I have with the subclass being UIViewController
But I am unable to make the tableview cells static via IB since it is not a subclass of UITableView Controller.
EDIT per NSJones Code:
It seems to be going somewhat in the right track. However the view still blocks the table. If I remove the view from the storyboard it will only display the table.
You can make a view hover the same way you make any real thing hover; Hold it up with something invisible.
Basically what you want to do is create a clear UIView (with user interaction disabled) that is the size of your view controller's view, and add it as a subview to your view controller's view property. That way it sits invisibly on top. then you can add a subview to that clear view and that subview won't move.
Edit:
It seems this nice clean approach won't work for you since you need your view controller to be a UITableViewController. The answer for this slightly more complex approach is to use a delegate method for UIScrollView which also works for UITableView. Apple has a fantastic demo of this concept in the WWDC2011 - Session 125 - UITableView Changes, Tips, Tricks video. If you can watch it I highly recommend it. The meat of this issue begins at about 36:10.
But to sum it up you implement the scrollViewDidScroll: delegate method. And handle the movement of the tableview by adjusting the position properties of the view. Here I am keeping an UIView property named viewToKeepStill still using this method.
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
// CGFloat stillViewDesiredOriginY; declared ivar
CGRect tableBounds = self.tableView.bounds; // gets content offset
CGRect frameForStillView = self.viewToKeepStill.frame;
frameForStillView.origin.y = tableBounds.origin.y + stillViewDesiredOriginY; // offsets the rects y origin by the content offset
self.viewToKeepStill.frame = frameForStillView; // set the frame to the new calculation
}
Instead of adding it as a subview of the table view, add it as a subview of the superview of the table view; that way it won't scroll.
So instead of this:
[tableView addSubview:viewController.view];
Do this:
[tableView.superview addSubview:viewController.view];
Assuming you want something that is visible full-time with the table, start with a view which contains both the menu view and the UITableView. Make the table smaller so it ends where the menu view begins. The table view can work with less vertical space.
If you have your UIViewController's view to be your table view then your table is going to span over the whole screen, so you won't be able to add anything on top of it.
Why not try the following:
1) create a new UIViewController
2) add a view on top where you want your menu
3) in the space left under just drag a table view from the component library
4) don't forget to set the 2 table view delegates to be your view controller class
that's about it?

Swipe to change views

Is the following easy to code?
I have a tableview and when the user selects a cell a detail view is loaded.
I want to allow the user to navigate throughout the items/detail-view representing the items in the tableview by left and right swipes, working in the same way as e.g. the home-screen of the iphone (e.g. while swiping, one page is moving off the screen and the next appears).
I have seen this implemented in the MobileRSS-APP, so it is possible, but I just have a hard-time figuring out the way to do it properly.
Thanks a million in advance! I am still trying to find my feet with cocoa-touch...
This is not a secret, Apple provides the sample code called the PageControl that demonstrates exactly what you want to achieve:
This application primarily demonstrates use of UIScrollView's paging functionality to use horizontal scrolling as a mechanism for navigating between different pages of content.
I implemented it in many of my apps.
The iphone home screen (springboard) works with a scroll view set to paging enabled.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)];
[scrollView setPagingEnabled:YES];
Then, lets say there's two pages of apps to swipe through - you set the content size of the scroll view to twice the width of your view:
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width*2, self.view.frame.size.height)];
And thats how that is done. :) I don't know if its the same for the MobileRSS-APP.
Things to bear in mind:
This isn't the default way a table view works. You might get your app rejected by apple. A table view is meant to work by clicking.
You could probably replicate the functionality without using a scroll view using touches methods and the navigation controller. A good tutorial describing how to detect swipes on your view is here: http://www.dosomethinghere.com/2009/07/23/simple-swipe-detection-in-the-iphone-sdk/
In the last method in that tutorial where there is the NSLog("swipe right") you could replace that with [self.navigationController popViewControllerAnimated:YES] which would replicate pressing the "back" button in the navigation bar.
I don't know what you could do for swipe left though..... if you wanted to do this on the table view you'll have to do some complicated maths determining how far the table view has been scrolled. Or you could test for touch events on the cells themselves, but thats something you wil have to look into. :)

UIScrollView always bounce upwards and does not show scroll bar in iphone

This is probably simple but I do not seem to get it to work. I have a view and inside it I have a scroll view and inside it I have a view with some labels and a button. the height of the text inside the labels changes according to some condition so I need to scroll down to see it. But whenever I try to scroll down it bounce back up without giving me a chance to view the rest of the view.
Basically, I want when I scroll down, the view to remain down as it normally should. Besides I do not see the scroll bar at all when I'm scrolling.
I know I probably do not understand how scroll views work, so I'd appreciate any help to explain to me the behavior of scroll views.
P.S. I built my whole view in a nib file and this specific setup That I mentioned at the beginning is based on a suggestion from one question I read here.
Thanks, Mohsen
you need to set content size of your scroll view
[scrollView setContentSize:CGSizeMake(360,1000)];
you can make the content size dynamic as per your calculation.

How to display scrollbar in UITableView

I want to display some kind of indication to guide user to scroll.
Usually when we touch the UITableView scrollbar appears if needed. But I want this scrollbar indication already displayed on my tableview.
How is it possible to do so?
If you have a table view that goes offscreen, you can call
[self.tableView flashScrollIndicators];
and they will flash to show the user that they are there. This is usually put in viewDidAppear.
(If you inherit from UITableViewController then you will have a self.tableView instance variable, if not then substitute another UITableView.)
If you a scroll view's entire contents fit within its view then no scroll bars are displayed; to test this display a table view with only one cell. If the content size is larger than the view's frame then scroll bars will be displayed; only then will [self.tableView flashScrollIndicators]; actually flash scroll indicators.
There's no way to force the scrollbar to appear, short of messing with the internals of UITableView(which you shouldn't do), or redesigning your own table view class.
Per the documentation of UIScrollView's showsVerticalScrollIndicator property: "The indicator is visible while tracking is underway and fades out after tracking."