Nested uiScrollViews with Cross-Directional Scrolling - iphone

I would like to nest two uiScrollViews, I want to put a uiImageView into one and have it scroll horizontally (Scroller A). This is paged and contains images – I have this working OK already. I need to have another uiScrollView (Scroller B) that contains the above scroller A and also other content, like logo, text and buttons. I would like scroller B to be able to scroll vertically (scrolls all content including scroller A ).
Please see image for clarification, red arrows show scroller A, blue is scroller B
Image showing more details
I’m not sure how to add these and what order the scrollers need to be added, I have attempted this a couple of times with strange results, I'm hoping someone can point me in the right direction please.
A similar app would be the apple app store app.

Keep a vertical scroll view add a fixed size view (which contains your horizontal scrollview) on it and increase its content size accordingly.each view will have Preloaded horizontal scroll view.
for(int i=0;i<10;i++)
{
y=i*110;
secondScroll=[[UIScrollView alloc]initWithFrame:CGRectMake(x, y, 320, 100)];
[secondScroll setContentSize:CGSizeMake(600, 45)];//to enable scrolling content size is kept more the 320
secondScroll.backgroundColor=[UIColor greenColor];
[self.firstScroll addSubview:secondScroll];
[secondScroll release];
[self.firstScroll setContentSize:CGSizeMake(320, self.firstScroll.contentSize.height+110)];
}
first scroll is added on xib second scroll is created by code

Related

How to make a scrollable view in iOS?

i am looking to create an "options" page for my application and because they are many , the screen of the phone is not enough to show.
So i need the user to be able to scroll down the view to see more options till the last. I know i should use the scrollview , but i dont know how.
All the tutorials i ve found are about scrolling all over the screen , zooming , scrolling from left to right , but nothing on how u can create a simple page scrolling up and down.
How exactly do i do that? Do i make many .nib files and somehow i connect them? Do i make a big .nib file?
Can someone guide me to a tutorial on that?
Use ContentSize property of UIScrollView to scroll what ever area you want. i.e.
take UIScrollView add it on UIView with exist height of iPhone. i.e. max 460.0
So ScrollView frame will be max (0,0,320.0,460.0).
Now after adidng ScrollView to View set ContentSize property to upto scrollable area.
[self.mainScrollView setContentSize:CGSizeMake(self.mainScrollView.frame.size.width, 1000.0)];
UIScrollView *mainScroll = [[[UIScrollView alloc]initWithFrame:CGRectMake(x,y,w,h)]autorelease];//scrollview width and height
mainScroll.scrollEnabled = YES;
mainScroll.userInteractionEnabled = YES;
mainScroll.showsVerticalScrollIndicator = YES;
mainScroll.contentSize = CGSizeMake(width,height);//width and height depends your scroll area
..........
//add subviews to your scrollview.....
[mainScroll addSubview:view1]
............
[mainScroll addSubview:view2]
..............
[mainScroll addSubview:view3]
[self.view addSubview:mainScroll];
Note :: contentSize property determines your scroll
area.Scrolling
enabled only if your scrollview content larger than scrollview height..
You could use a Table View with static Cells, that will scroll automatically if it needs to, much easier. Also with a Table View you can choose to scroll up, down, left, right, set bouncing etc from the Attributes Inspector.
Make only 1 nib file.
give height of scroll view large as you want.
then place your buttons , textfeild on scroll view
There are two ways :
make settings bundel for your app check this Press Me
to make UITableView with custom cells >> it is easy if you use
Interface Builder Press Me

IOS UIScrollView: Cannot scroll until the end of the content

I am trying to generate a scroll controller in a window with the UIScrollView class, which will contain numerous UIButtons, placed vertically. I set the size of the scroll view equal to the current view controller's root view, so that the scroll view covers the entire visible window. Then I generate the UIButtons I am going to add to the scroll view: I add each UIButton just in the below of the previous UIButton and I add the height of the current UIButton to a variable called "totalContentHeight". Finally, I set the height of the contentSize of the scroll view to this value, in the following line of code:
self.scrollViewForNewsButtons.contentSize = CGSizeMake(self.view.frame.size.width, totalContentHeight);
totalContentHeight is equal to numOfButtons*eachButtonsHeight after I add all the buttons to the scroll view.
The problem is, in the simulator, when I run the app and scroll until the end of the last button and release the mouse, the last two buttons bounces back such that they lie outside of the visible window. It is somewhat hard to express with mere words, so here are the images:
1)This is what I get when I scrolled until the end of the content and held the content at the last possible position it could be pushed:
2)This is what I get after I released the mouse and the scroll view bounced back to its final position:
As you can see, the last two buttons are drawn outside of the visible area. It is like the scroll view's area covers the whole window plus the button area of the IPhone. I could not find a reasonable explanation for this. Am I setting the area size wrong or am I missing something else?
just set content size with calculation with your total button and its height...For Ex..
float yheight = totalButton * yourButtonHeight;
[yourScrollView setContentSize:CGSizeMake(320, yheight + 44)];
try this code...
And if you set the scrollview frame size the same as
self.view.bounds

UIScrollView only scrolls with text

I recently updated my xcode to 4.5 but now my UIScrollView Doesn't work anymore, in my previous xcode I made the scrollview at the exact same way and placed a imageview background and some buttons in it, they scroll along when I scroll.
Now with this new xcode when I place something in it, it doesn't scroll at all. Only when I put textview in it and make the text longer then the screen then it will scroll, but even then when I place a button on it the button won't scroll along, just the text. It's realy annoying and I don't know what Im doing wrong.. I've been trying to find a solution to this all day.
my ScrollView is placed in my view and got size 320,480.
in my ViewDidLoad I have:
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 481)];
I also have a picture to make my setup more clear, When I run the project in this picture it does scroll because of the text length. the image background is 320x960 but the picture doesn't scroll along it should go to the bottom where to color becomes more dark.. I hope you understand what I mean.
Extra
I made a video showing what I do, showing that it doesnt scroll when I put something in it
http://www.youtube.com/watch?v=rzYTWLiIC8g&feature=youtu.be
set your scrollView contentSizes height more than its original height then it would be vertically scrollable for sure.
Try this -
[scroller setContentSize:CGSizeMake(320, 800)];
Then see it scrolls or not.

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 Horizontal Scrolling

I am trying to create an app with horizontal scrolling, so that one would be able to scroll horizontally through a series of images. I watched the WWDC Session 104 video on this, and while they made an interesting app, they flew through the basics of it very quickly.
I understand using the UIScrollView, and that I have to enable paging. After that they say that I should add more views as subviews of the scrollview, but I am not clear on how to do that. I am also not clear on how I add my images to those views.
As you can probably tell I am pretty new at this so any help would be appreciated.
You want to look into UIImageView. It's a view specifically for holding images.
When you add your images, you want to set their rects (probably using initWithFrame: for each UIImageView) so that:
the first image is at 0,0
the second image is at 320,0
third is at 640,0 (etc)
I.e. each image is 320 pixels right of the previous.
The final step is to set the contentSize for your UIScrollView -- this is a CGSize which describes the total size of the scroll view.
If you have 3 images, you would then set it to (320*3) * 480 using e.g.
myScrollView.contentSize = CGSizeMake(320*3, 480);
A lot of people, when they initialize the scroll view, have a for loop or similar which steps through the images they want to display. These for loops tend to look something like this:
CGFloat scrollWidth = 0.f;
for (UIImage *someImage in someNSArrayWithImages) {
UIImageView *theView = [[UIImageView alloc] initWithFrame:
CGRectMake(scrollWidth, 0, 320.f, 480.f)];
theView.image = someImage;
[myScrollView addSubview:theView];
[theView release];
scrollWidth += 320.f;
}
myScrollView.contentSize = CGSizeMake(scrollWidth, 480.f);
This way you'll get things lined up and you'll get the content size for you at the same time.
If you want to make it so that the scroll view "intelligently" scrolls to each image and stops when people slide left/right, you can do myScrollView.pagingEnabled = YES.
Hope that helps get you going.
Assuming you have "infinite" images, putting them all there at or before launch time in a huge UIScrollView will not be an option. (there is a limit to the size of a UIView)
The way I solved it: Make a UIScrollView covering the whole screen. It's content should be a UIView of 3*320 width and 480 height, extending 320px left and 320px right.
Put 3 UIImageView's in it, left, middle and right. Set paging=YES, so the uiscrollview clips to the 3 "pages" you've created.
Make sure your class is the delegate of the uiscrollview, and listen for
-(void)scrollViewDidEndDragging:(UIScrollView*)sv willDecelerate:(BOOL)notFinished
-(void)scrollViewDidEndDecelerating:(UIScrollView*)sv
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView*)sv
and make the appropriate transitions on hitting paging boundaries; shift images and set ContentOffset so you're looking at the center image again.
I suggest you make this first, and only then read on...
Then you will hit on a bug, documented here UIScrollView - (bounces = NO) seems to override (pagingEnabled = YES) and here http://www.iphonedevsdk.com/forum/iphone-sdk-development/935-paging-uiscrollview.html, which makes that you cannot disable bouncing and have paging enabled at the same time. So enable bouncing, and subclass UIScrollView, overruling setContentOffset in there to prevent bouncing. (having bouncing really enabled will make for a rather unusual user experience)
Have a look at Apple's PageControl sample code. It's fairly short and easy to follow so you'll get the gist of setting up a project where multiple view controllers are loaded as you swipe horizontally.
Once you have this setup then it's the view controller's responsibility to load its own content (in your case, an image). You should make sure you understand how to load images first (using threads, etc) before you tackle paging, etc.
Think of it as two independent tasks. The view control is responsible for loading and displaying an image. The scroll view with paging just tells the appropriate view controller when to load itself (it doesn't care what the view controller does once its loaded)
Good luck!