4 directional scrollview with paging - iphone

I need to implement a scroll view which (on a button press) will page either up, left, down or right depending on which button was pressed. Also the user can indefinately page in the same direction which will load the views in a kind of carousel. So I have 3 viewControllers.... viewController 1 is shown first....The user presses left, it shows viewController2, left again shows viewController3, left again is back to viewController 1 etc. and the same for up,down,right.
Does anyone know a good way to implement this? Im open to all suggestions.
Many thanks
Jules

Edit - second attempt at a clear explanation:
Consider this matrix.
This 3x4 matrix is the content area of your scroll view. With paging enabled, your scroll view will stop on one of these "cells", e.g. 2,1. That portion of the scroll view will be visible.
If you want each "cell" to be controlled by it's own view controller, then pre-generate all the view controllers (and their views), and then add all of their views as subviews to the scrollView.
You would populate this scroll view with whatever view you wanted to show at any given location. Set the frame of each view relative to the scrollview's origin. So if the cells were 320 pixels wide and 480 pixels tall, the frame for cell 1,3 would be CGRectMake(1*320, 3*480, 320,480).
When the scrollView ends deceleration, you can get it's contentOffset property, do some arithmetic and figure out which cell you're in.
To get the wrap-around effect, you'll have to do some trickery. You might put an extra cell at the end of each row and column, and if you find yourself in that cell, just set the scrollviews' contentOffset to the corresponding cell at the beginning of the row or column.

Related

How to move a subview to front and have existing view shift up to make room?

I have a collectionview that takes up the whole screen. Once the user clicks a cell and does stuff in the detail view, they are sent back to the first collectionview screen. At this point, I am bringing a view to the front that is a pseudo-tabbar. I want to shift the collection view up to accommodate this new view. Right now, it is just blocking the bottom row of collectionview cells. Thanks in advance!
Put the pseudo-tab bar in the initial view and constrain your collection view's bottom to the top of the tab bar.
Set the tab bar's initial height to 0. Don't just set it to hidden, because that keeps the view's original height.
When the user returns to the collection view, set the tab bar's height to the desired value. Animating it in will look even better.

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

Progressively reveal and slide UIView down from behind another UIView

I have a rectangular, menu-style view (view 1) laid across the window approx 100 px down (i.e. there is space above it in the window), and need to animate drop-down content (view 2) appearing lower down the screen from view 1. I need the animation to start at the bottom boundary of view 1 - much as with the iOS 5 notification pull-down, except from a specific point further down the screen.
I can't simply slide view 2 in from off screen, since for various reasons I can't overlay a UIView that would hide its motion until it reached the lower edge of view 1.
I've checked out this answer - Programmatically reveal a UIView - but I don't believe it's appropriate since I want the menu to slide, not be revealed from a static start point. And, as pointed out, I can't "hide" the sliding view with another view.
How do I slide down view 2 so that it is revealed as it emerges from the lower boundary of another view, similar to the io5 notification pull-down?
Contain both subviews in a superview with it's bounds clipped. So you'd have your superview (let's say app window), and within that a view (with bounds clipped). Let's call this a container view. This container would originate at whatever Y coordinate your current inserted/always visible view does, but it's height would extend tall enough to encompass the fully-expanded "sliding" third subview.
So within your container view, you'd place your first always visible view (view 1) at coordinates 0x 0y, and then you'd insert your sliding view (view 2) beneath that, with the frame y offset for view 2 set accordingly and at sufficient negative value to hide it completely by means of the over-layed view 1 and the clipped bounds of the container view.
As the user drags (or whatever means you use to disclose your 'sliding' view), the 3rd view slides down from below the always present view, but always stays within the overarching clipped view. Viola.

UITableViewController, getting bounds of visible area

I've got this question. In my app I have many cells. When user clicks on something I'm loading VC and pushing it. To indicate this behaviour I'm displaying a subview which informs that now application is loading. Problem is, when user scrolls down and taps on cell my subview still is on the top of the tableView thus user isn't seeing it.
I need to change frame of my subview so my user can see it. I want this frame to be the center of the current view. How I can do that?
Fore example: My content is 800 pixels worth of height, now I'm displaying at 400 pixels subview with specific information about loading. When my user scrolls down to a cell that is at 2400 pixels, I'm still displaying subview at 400 pixels and thus it is unviewable by user.
I was trying to calculate new frame.origin.y by checking y of a cell that is tapped. Problem is the cell at 2400 pixels could be the first cell user is seeing or the last one, so how I can get the middle of the screen?
Edited with some screens:
When I select first time:
When I select after scrolling down big time:
What it looks like you have done here is added the loading view as a subview to the UIScrollView. You need to add the loading viewController into the parentView after the scrollview.
If this cant be done because your viewController is a subclass of UIScrollview, change it to a regular UIViewController subclass but implement the scrollView protocols and then do as i have said above. Other than that you would have to map the frame of the loading ViewController to the offset on the scrollView-not a good idea.

Is there a way to achieve parallel scrolling of two tableview?

Let's say, i have two tableview inside a scrollview. After i scrolled up & down tableview1, and then touch and swipe to scroll the scrollview horizontally to tableview2, i want tableview2 to have the same vertical (up & down) position as tableview1. is there any way to achieve that?
thanks
You can put code in the UITableViews' viewWillDisplay: methods that grabs the other table view's scroll position (called a "content offset" in scroll view parlance) and calls setContentOffset:animated:. This way, whenever either scroll view will appear on the screen, it will automatically scroll to the other view's position.