Swipe to change views - iphone

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. :)

Related

iOS /Obj-C UIScrollView and PageControl not working

I am attempting to implement a UIScrollView with a UIPageControl following the guide on this website:
http://www.iosdevnotes.com/2011/03/uiscrollview-paging/
In opposite to the guide, I am implementing this in a storyboard project, and using XCode4.5.2. In addition to the code in the guide, I have added at the beginning of the #interface, and inside the viewDidLoad method in the implementation, I have added scrollView.delegate = self.
With only the code and IB-objects described in the guide added to my app, it doesn't allow me to scroll at all when I test it on my iPhone. The only scrolling i can do is by swiping my finger over the UIPageControl, which makes the "white dot" in the PageControl move one spot towards the direction I was swiping, and with no visible changes in the ScrollView. In the guide we add different colours to the backgrounds of the views in the scrollView -- none of these colours show up at all.
I have tried debugging by putting NSLogs in my code to see what methods are reached by the app. Adding an NSLog (#"View did load"); right after [super viewDidLoad]; in the viewDidLoad method atop the main view controller doesn't output anything to the terminal. Does this mean my app doesn't load up properly?
Thanks in advance!
Do you have multiple pages added to the scrollView? Scrolling is default off if you only have one page worth of content. Ensure that the loadScrollView method is called and also add this:
scrollView.pagingEnabled=YES;
If you are interested I created this class for paging with the scrollview
https://github.com/andrealufino/ALScrollViewPaging

Gain control over scroll view

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 :)

Can we add a scroll view inside UITableViewCell?

I have requirement where I have to show some images which are differentiated according to Groups they belong to. I have used a table view to view images listed under groups. User has to scroll horizontally to view more images in a particular group.
Can we add a scroll view to tableview row to allow user to scroll list of images horizontally?
I searched a bit, some comments say its not allowed in apple's HIG some comments say
You can add a UIScrollView to a UITableViewCell and as long as you set the contentSize property of the UIScrollView correctly then the UIScrollView will scroll correctly in the horizontal axis
May I get any confirmation on this ??
Or any alternative approach to achieve horizontal and vertical scrolling for different data without using tableview
Yes it is definitively possible and reasonable.
Here is an excellent tutorial by Felipe Laso that explains it step by step:
How To Make An Interface With Horizontal Tables Like The Pulse News App: Part 1
How To Make An Interface With Horizontal Tables Like The Pulse News App: Part 2
BTW, the approach described in that tutorial is way more efficient than adding a UIScrollview to each cell.
Of course you can add scrollView in tableView.
UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 100)];
[cell.contentView addSubview:scrollView];
Now you can set properties for scroll view accordingly.
Sure, this is possible. A UIScrollView inside a UITableCellView will work fine - the HIG says no, probably because it'll be hard to use. The user would have to accuratley scroll either up/down, or left/right and it might be annoying. Shouldn't take long to knock together a quick test.
I have an app with 2 scrollviews - one that allows horizontal scroll, and then inside that another scrollview which allows vertical scroll. The idea is that the user can flick up/down a page, then also flick left/right across pages.
It's not that nice to use, but it's what my client wanted ;)
To make a UIScrollView only respond to horizontal or vertical scroll is all about setting the correct contentSize. Hope this is some help.

Can't touch UITextField on UIScrollView

I know this has been talked about a lot. I think I've gone thru every question on this site, and still have not been able to get this working.
I'm new to developing but I have a good sense of what's going on with all of my code. I definitely don't have a lot of experience though, this is my first iPhone app.
I'm making a data entry field that is comprised of multiple UITextFields within a UIScrollView. I'll avoid explaining the other details for now, as it seems its a very basic problem. Without a scrollview, the textfields work perfectly. I can touch the textfield and the keyboard or picker view show up appropriately. When I add the textfields to a scrollview, the scrollview works, but then the text fields don't receive my touches.
Here's the key: When 'User Interaction' is ENABLED, the scrollview works but the textfield touches are NOT registered. When 'User Interaction' is DISABLED, the scrollview doesn't work, but the textfield touches ARE registered and the keyboard/picker pops up.
From the other posts I have seen people creating subclasses and overriding the touches in a separate implementation. I've seen people using custom content views (subviews?), I've seen some solutions that are now obsolete since the APIs have changed in newer versions of the SDK, and I am just completely stuck.
I will leave out my code for now, because maybe there is a solution that someone has without requiring my code. If someone needs to see my code, I will put it up. My app is being written in the 3.1.3 SDK.
If anyone has ANY information that could help, it would be so greatly appreciated.
Here is what worked for me in Xcode 4.3.3.
In the storyboard, select your scrollview. Select Attribute Inspector on the right side. Uncheck Delays Content Touches.
It sounds like you're using IB to do a lot of your UI layout. If you take a programmatic approach you could set-up the following view hierarchy which should work.
Your view controller object managing your scroll view and your text fields should have a UIScrollView object and a UIView object (in addition to any UITextField objects you need). In the loadView method of the view controller class, allocate and initalize the UIView object and add your text fields to it as subviews. At the end of the method, allocate and initalize the UIScrollView object then add the UIView to the UIScrollView as a subview.
As an example, if your UIScrollView object were called scrollView and your UIView object called mainView the following lines at the end of the view controller's loadView method would properly set up the scroll view with the main view with the text fields on it:
scrollView = [[UIScrollView alloc] initWithFrame: [[UIScreen mainScreen] bounds] ];
scrollView.backgroundColor = [UIColor whiteColor];
scrollView.contentSize = mainView.frame.size;
[scrollView addSubview: mainView];
self.view = scrollView;
You may need to enable / disable user interaction for both the scroll view and text fields as necessary.
If possible you might best using different touch mechanisms for each process (scrolling and textfield input).
Maybe you can check the time differential between touch start and end such that you can detect the difference between a drag (scroll) and a tap (text input).
Having said that if you propagate the touches up from the textfields to the scrollview you should be fine. One thing I use is:
[myObject addTarget:self action:#selector(itemTouchedUpInside:) forControlEvents:UIControlEventTouchUpInside];
which passes the object touched so you can identify it and act accordingly.

Nested UIScrollView-iPhone photos application

I have been facing the same nested UIScrollView problem for long time.I tried some open source codes like Scrolling madness ,three-20 and others but all fails finaly.I am trying to make a photo Viewer application same as iPhone.For that I have created the structure like this:-
1)one View controller.
2)on view of view controller one UIScrollView (i.e inner/parent scroll view) as a child.
3)on inner/parent scroll view number of child scroll views(i.e. outer/child scroll views) ,each represents one page of photos application.
4)On each scroll view one image View on which i am displaying my image.
So what I want is when user scrolls the outer scroll view it should scroll horizontally with all the child views so I will get the look and feel of paging in photos application.Also when user is on one specific image(i.e. child/outer scroll view) he should be able to zoom in/out,swipes and perform single/double tapping.I was able to make it work in sdk 2.1,but it dosnt work since sdk 3.0.Please tell me the idea behind your project.Means which scroll view you are subclassing ,in which view to detect touches.How this completely child - parent relation should be.
If possible provide any sample code also.
There is a WWDC session from 2010 that deals with this very issue.
Here's the short of it:
You need a single scroll view that is paginated and scrolls horizontally. Each "page" of that scroll view is another scroll view containing a photo.
First, it looks like you want to subclass UIScrollView? Every interaction method you need is provided for you in either the delegate callbacks or the touch methods. (Many of Apple's more advanced classes, such as UIScrollView, react poorly to subclassing.)
Second, it sounds like you have a first responder problem. IOW, your innermost scrollview isn't getting the first crack at the touch events.
Andrew
I also struggled with this for a long time trying samples you mentioned. I could finally figure it out with the samples provided by apple (iphone dev center).
http://developer.apple.com/iphone/library/samplecode/Scrolling/Introduction/Intro.html
http://developer.apple.com/iphone/library/samplecode/ScrollViewSuite/Introduction/Intro.html
The first one is pretty basic and probably what u already have. The second one is all about zooming, etc. Just study these and the samples you already have, I think you will be able to figure it out. On specific topics just come back here search for answers or post another question.
EDIT: I forgot this one check out these examples by Andrey Tarantsov hosted on github. This is what you want... http://github.com/andreyvit/ScrollingMadness