UITableViewController, getting bounds of visible area - iphone

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.

Related

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 inside UITableView

i got a tableview and as a header i use amongst other things a scrollview.
All work ok in terms of scrolling apart from the fact that when i scroll down (or up) the tableview the scrollview "loses" the x,y coordinates.
for example if i scroll the scrollview on the headerview right to left (or vice versa) then the scrollOffset.x gets a value.
if i start scrolling the tableview then this value goes back to zero (although the scrollview doesnt lose the paging). If i go back to the scrollview and start scrolling again the scrollOffset.x gets its correct value again.
Anyway to "keep" the scrollOffset.x value when i scroll the tableview?
thanks
Considering that a tableView is a scrollView subclassed it seems like the problem is that scrollOffset.x is set by whichever scrollView you're currently scrolling inside of. Try adding tags to your table view and scroll view and add a variable to keep up with the scrollOffset.x for only the scrollView in your header.

4 directional scrollview with paging

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.

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.

UITableView details as a subview

I have a UITableView in iPhone with enough cell to make it scrollable.
I would like to have a subview display whenever I click on a cell, rather than using the navigation controller behaviour.
The problem is that I cannot calculate the CGRect exactly to have the subview always centered in page, because the CGRect is calculated from top of table, and if I scroll table and click cell, the subview will be added out of screen.
The solution could be easy, but I don't know if it's possible: identify the portion of the current viewable area of the UITableView and obtain in some way the frame and therefore origin and size, then build a subview based on such coordinates.
Do you think it's possible without writing not too much code ?
thanks
Leonardo
A simple solution is to not add your sub view as a subview of the UITableView but of its parent (or the main application window). So instead of doing something like:
[myTableView addSubview:mySubView];
do:
[[myTableView superview] addSubview:mySubView];