I have few text fields in sectioned table view. When i rotate the view gets rotated according to the orientation but not getting filled up according to the screen. For instance i have set the width using CGRectMake method for portrait as 70.0 but when it is turned to left the size of the text box is the same and not getting expanded according to the width.
I have the widths setup in my tableview code according to the orientation. Please tell me how to reload the tableview after the orientation change or what is the way to make the CGRectMake to change automatically based on the orientation for each component in table view.
Related
I have a problem with autolayout. The Table View below the Image View should resize to fill the whole space below when the App runs on an iPhone 5, but it doesn't. What is the problem?
Your table view should have a vertical spacing constraint to the image view and another one to the bottom of the screen. It should have no height constraint.
After Edit:
I'm not sure what all your constraints are. It seems that something needs a fixed height (or some way to tell the system what the relative heights of the image view and table view are). It worked fine for me to give the image view a fixed height, and with these constraints for the image view and table view:
image view:
table view:
How Can I make the green area of the screen shot of my app be able to scroll with the paging animation and page indicators?I would like for me to add more icon-buttons to it with keeping the header the same size.
First you need a scroll view and your view has to be inside of the scroll view.
Then you need to enable paging on the scroll view
[scrollView setPagingEnabled:YES];
If the value of this property is YES, the scroll view stops on multiples of the scroll view’s bounds when the user scrolls. The default value is NO.
If you want to have page indicators you need to use UIPageControlwhich you will have to manage yourself as far as I know. You could always check after scrolling (see UIScrollViewDelegate ) which page you are on based on the contentOffset property of the scroll view.
I have a UIScrollView in which vertical only scrolling is enabled. I'm displaying a grid of buttons (similar to the photo viewer image grid). The grid has to be drawn differently based on screen orientation, so that all of the screen real estate is used. Given the size of my buttons, I can fit 3 per row in portrait, and 4 per row in landscape.
I reposition all of the buttons in: willRotateToInterfaceOrientation:duration and then call: setContentSize: on my UIScrollView. Everything seems to work just fine, with the exception of the auto-scrolling that occurs after the call to SetContentSize:. In other words, let's say I was in portrait, and scrolled 3/4 of the way down the list, when I rotate to landscape, it auto-scrolls all the back up to the top.
The interesting thing is, in the same scenario, if I were to do a small flick scroll up or down, and then immediately rotate the device, the scroll view redraws correctly, and retains the current scroll position!
So, to be clear, the culprit here seems to be SetContentSize:, but obviously I have to call that for the scroll view to scroll correctly.
Any ideas on how I can retain the current scroll position?
Thanks!
You might try implementing the UIScrollViewDelegate method scrollViewShouldScrollToTop:, which tells the caller whether to scroll to the top or not. You may have to have some flag in your delegate that indicates if a rotation is underway or not, because under normal conditions you may actually want the ability to tap the status bar and have the scroll view scroll to the top.
If, on the other hand, you don't ever want the scroll view to scroll to the top automaticlly, simply implement that delegate method and have it return NO.
I had this problem, just did this and it works well for me
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
//calculate percentage down scrollview currently at
float c = self.scrollView.contentOffset.y / self.scrollView.contentSize.height;
//reposition subviews in the scrollview
[self positionThumbnails:toInterfaceOrientation];
//set the new scrollview offset to the same percentage,
// using the new scrollview height to calculate
self.scrollView.contentOffset =
CGPointMake(0, c * self.scrollView.contentSize.height);
}
In my case, I have a scrollview with a fixed width to device size, and variable height
I have a TabBarController with 4 views, and one of them is a scrollView. If i load this view, and then change the orientation of my device from portrait to landscape, the scrollview responds to the touches only 'till the pixel 320.
If later i go to another view, and then come back to the first, the scroll view works well even in landscape.
How can i adjust this?
Your scroll view is probably not set to automatically adjust its height and width. If your view is built with Interface Builder, use the Autosizing section of the Size Inspector to set the struts & springs. Otherwise, if you're building your view programmatically, you'll need to set the autoresizingMask property to something appropriate.
I understand that Apple will do a kind of autoresizing thing when iPad / iPhone change orientation and you can set views' autoresizing masks.
But what if the views' resizing is not that simple?
for example, I have a TableView and each cell has different number of letters. Assuming in Landscape mode, the TableView has perfectly built so that the TableView does not need to scroll down and all cells are listed perfectly ( I calculate the right font size for the texts in each cell depending on the width info)
If now I change the orientation to Portrait, yes, the TableView is narrowed, and the cells are messed up, they are narrowed (of course I want), but the TableView need to scroll down to see all cells. I know know the font sizes should be smaller so cells can be shorter
My question is:
So I have recalculate all font sizes if the orientation is changed? If I have 20 such TableViews laid in a paging-enabled ScrollView, I have to do this for all 20 * 10 cells each time when the user change the orientation??
Thanks
The answer is YES, either you need to create a two view OR change the existing controllers frame. This is the only way to handle orientations.