No vertical scroll in uiscrollview w/ uiimageview subviews - iphone

I have uiimageviews as subviews for uiscrollview. I made my uiviewcontroller resize the scrollview contentsize and offset similar to how it was done here: http://github.com/andreyvit/ScrollingMadness/tree/master. The only difference is that I don't want my image views to take up the whole screen but try to stretch proportionally so I used
scrollView.contentMode = UIViewContentModeScaleAspectFit;
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
view.contentMode = UIViewContentModeScaleAspectFit;
view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
and a few other modifications. Now, the images are expanding proportionally and it looks fine without a nav bar but if I push the ScrollingMadnessController, it'll create a nav bar which will cause vertical scrolling.Is it even possible to disable the vertical scrolling?

As far as I know, vertical scrolling is disabled if the height of the scroll view's contentSize or the content in the scroll view does not exceed the frame's height of your scroll view. In other words, if this is the case there is no reason to allow for vertical scrolling (the same is true for horizontal scrolling obviously).
If you enable vertical bouncing, however, you still might get the impression that vertical scrolling is enabled, but you are not really scrolling content in this case.

Related

UITableView contentInset makes table view scroll horizontally in addition to vertically

I'm creating a UITableViewController in code and pushing it on top of the navigation stack.
It's table view is intended to just show a simple list of text items.
I need to add some contentInset to my table view which I add in the init method of my UITableViewController
self.tableView.contentInset = UIEdgeInsetsMake(7.0f, 5.0f, 7.0f, 5.0f);
However, when I load the table view it seems the left and right contentInset have actually stretched the width of my table view by 10. I'm now seeing a small horizontal scrollable area. I don't want any sort of horizontal scrolling on my table view. If I remove the contentInset code, my table view behaves plainly i.e. simply provides for vertical scrolling. How I can keep just like that but with my contentInset in place? I tried reducing my contentSize.width by 10 in viewWillAppear, it had no effect.
This seems to be a duplicate but with no acceptable answer: UITableView ContentInsets scrolling content horizontally
In the mock I have marked the desired contentInset with dashed line ---
Thanks.
I ended up setting just the top and bottom insets. To achieve the left and right inset look and feel, I created custom cell as wide as the screen. But the actual cell content was restricted to a slightly narrower subview within the custom cell. Thus, there was space leftover on the left and right of the subview.
Looks like you need to do 2 things:
Add the table view to a container view and make the table view frame thinner (to add the left and right borders).
Add thecontentInset only for the top and bottom.
Maybe you should set the bounces property of the scrollView to YES.
And do not set the contentInset.
Another way that could work, is that, instead of setting the tableView frame, you can set the frame for cell's contentView , something like this,
- (void) layoutSubviews
{
[super layoutSubviews];
CGRect frame = self.contentView.frame;
frame.size.width = frame.size.width * 0.9; //90% of total width
frame.origin.x = self.center.x - (frame.size.width/2); //center the contentView
self.contentView.frame = frame;
}
The using the above, u can add any left or right or left padding u need for the cell. and all the subViews will be added to the contentView , hence no problems there.
happy coding..!

I rotate screen manually to Landscape but the taskbar buttons dont use the new full width of 480, rather they only use the 320 portion of the bar

I rotate my screen to landscape mode
- (void)rotateScreen
{
[self.tabBarController.view setTransform:landscapeTransform];
self.tabBarController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
self.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 480.0, 320.0);
self.tabBarController.view.center = CGPointMake (240.0, 160.0);
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}
It all seems to work well,
The view and Navbar are rotated, the postion of the Tabbar changes position to the bottom of the screen.
The problem is that the buttons on the Tabbar do not use the full width of the screen rather they only use the space of 320pixles rather than growing onto the full width of the bar, which has become 480 pixels now.
Is there someway I can ask it to grow in width?
I have seen similar issues when the views you have added are added as subviews using the addSubView method instead of being pushed to the navigation bar.
That is the first thing I would review.
Did you anchor the tab bar to the right edge of the view? The anchors play an important role in sizing you view based on the parent.
Read about UIViewAutoResizingMask in developer documentation for more info.

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.

How can I draw in the "bounce" area of a UIScrollView?

I have a custom-drawn view that I include in a UIScrollView that scrolls horizontally. The view draws a background with lines extending horizontally, and some different background colors. When I scroll to the far left such that the scroll view "bounces", I see gray background color. What I would like to do is to draw additional background lines and colors into that area, so that it looks like the view goes on forever, but I can't quite figure out how to do this. I've tried setting clipsToBounds to NO for all the views, and drawing in an area outside the view, but this doesn't seem to work. How can I draw in this area?
I found the solution to this, at least in my case. I simply increased the size of the scroll view with an extra margin, then positioned the scroll view partly off the screen.
CGFloat scrollViewHeight = 300;
CGFloat preferredWidthOfContent = 500;
CGFloat gutterMargin = self.bounds.size.width / 2;
scrollView.frame = CGRectMake(-1 * gutterMargin, 0, self.bounds.size.width, scrollViewHeight)
scrollView.contentSize = CGSizeMake(preferredWidthOfContent + 2 * gutterMargin, scrollViewHeight);
contentView.frame = CGRectMake(0, 0, preferredWidthOfContent + 2 * gutterMargin, scrollViewHeight);
The content view has to know about the gutter margin width, and then draws the actual content in the correct place based on that. When the scrollView is "bounced", then the remainder of the content view is actually displayed.
This trick works because the scrollview is extending off the screen. If you wanted to use the same trick with a scrollview that did not touch the edges of the screen, you would have to simply place another view over the top of the scrollview to hide the extra space.
If you're drawing your lines in drawRect: method, there's no way to draw them outside of the view bounds. The property clipsToBounds only affects subviews, so, in theory, you could add a subview to your main view (the one displaying the content) with a frame that extends to the right of your view and draw the lines in that subview.
Another option is to add a subview to the scroll view and place it to the right of your main view. Then draw the lines in this subview. The scroll view will still bounce since it doesn't care whether there are still partially visible views in it, it only looks at the contentSize property to decide when to stop scrolling.
If neither option is suitable, describe in more detail what kind of lines you're drawing and what kind of appearance you would like to achieve.

Auto resize subviews on device rotation

I have all my subviews set up so that they are based on self.view.
EG: UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,(self.view.frame.size.width-20),(self.view.frame.size.height-90))];
however when the view rotates (shouldRotateToDeviceOrientation or whatever) the views all stay the same size. How can I make them change shape to fit? Can I do this automatically?
Thanks
Absolutely. Take a look at the autoresizingMask property. If you set your image view, in this case, to have an autoresizing mask of UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight, then when its parent view resizes (as it may or may not automatically do when your app rotates—you might have to set a similar autoresizingMask on the parent view), it'll maintain the exterior margins you set up for it.
Just in case you have a view in the bottom of parent view this should help:
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
Where self is your child view, that should be resized. If you do not set UIViewAutoresizingFlexibleTopMargin, then in horizontal mode you will not see your view, if it was in the bottom in vertical mode.
Also do not forget to set:
self.autoresizesSubviews = YES;
And autoresizing modes for all child view in your view. So that when it is resized, everything inside it also gets resized.
you have to [view setAutoresizingMask:...]