Re-size UIWebView after displaying UIToolBar - objective-c

I've got a ViewController with a UIToolBar at the top and a UIWebView underneath. The WebView fills the entire remaining portion of the View and is set to stretch, being anchored at the top and left.
The content of the webpage is 3-4 screens long, but when I scroll down through the WebView, I can see it all. However, if I dynamically hide the UIToolBar, then re-show it again, the WebView ends up being "too big" -- it's actually longer than the space available in the ViewController, so now when I scroll through my 4 pages of content, I get to the bottom and it tends to "bounce back" and won't display the bottom half inch of web content.
Is there a way to re-size the webview after hiding the UIToolBar?

webView.frame = self.view.frame
after the hiding of the nav bar should do the trick. also try
webView.scrollView.alwaysBounceVertical = NO;
to try to eliminate bouncing if it is having an undesirable effect. Cheers!

Resizing the webview isn't really necessary. You should instead play around with the auto resizing masks, like so:
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight

Related

UINavigationViewController changes the behaviour of scroll view in iOS7

I have a 'UIScrollView' that is supposed to display a list of images one next to the other. This is the code I'm using to add each image:
#define SCROLL_PADDING 10
#define SCROLL_DIMENSIONS 50
view.frame = CGRectMake(xValue, SCROLL_PADDING, SCROLL_DIMENSIONS, SCROLL_DIMENSIONS);
[scroller addSubview:view];
However, as shown in the image below, the images are loaded with a vertical offset. After some research I realised that this offset is the same as the height of the navigation bar's height.
Note 1: By default the images cannot be seen. I had to scroll up to make them visible.
Note 2: I shouldn't be able to scroll because the images should fit in the scroll view.
I decided to present the view controller modally instead of pushing it to the hierarchy of the navigation view controller and everything work as expected.
This problem only happens in iOS7. Any ideas why?
I came across this article, which clearly explains various changes in status bars and navigation bars on iOS7
As you can see in both of the images above, the position of the scroll view doesn't change. In iOS6 if the subview's frame doesn't change, it would be moved down to prevent it from underlapping the navigation bar. Since iOS7 it is expected that all subviews will underlap not only the navigation bar but also the status bar, which makes the location (0, 0) the top left of the SCREEN.
For some reason that I don't understand yet (it would be nice if somebody could explain), only the scroll view's subviews where moved down in the same way it was being done in iOS6. Hence making the subviews appear out of the scroll view's bounds.
To prevent the subviews from underlapping the navigation bar it is necessary to set edgesForExtendedLayour to UIRectEdgeNone as early as possible in the life cycle of the view controller
viewController.edgesForExtendedLayout = UIRectEdgeNone;

Make detail side of splitViewController scrollable?

I am trying to imbed a scrollView in the detail side of a splitViewController. Should the scrollView be added inside the 'View', as displayed in the image below?
Or does the 'View' need to be removed, leaving a View Controller and a Scroll View only?
Also, when I add the scrollView to the page, the bottom is being cut off, preventing it from scrolling all the way to the bottom. I also tried resizing the scrollView in the ViewDidLoad method of the View Controller to something extremely large such as:
theScrollView.contentSize = CGSizeMake(20000, 20000);
That did not work either. It seems that we can hold down the mouse and pan, but the scroll bars are always the same length. Thanks your help!
I have ALWAYS implemented scrollviews as the UIScrollView with a UIView inside of it, then your other elements (i.e. buttons, text views, etc...) SO the hierarchy would be
UIScrollView
UIView
UILabel
UIButton
.
.
.
Because you dont really have a top UIView WITHIN the scrollview, this is most likely why your
theScrollView.contentSize = CGSizeMake(20000, 20000);
line is not working as intended.

XCode Redraw portrait layout with double high status bar

I'm having this issue with several screens in my app, but I'll explain what happens to my home screen. Hopefully the solution isn't as complicated as I'm thinking it will be. So my home screen has a logo at the top, a label(title) under that, 3 horizontal buttons under that, and finally, settings and info buttons in the bottom left and right hand corner respectively when if portrait orientation. In order to allow for landscape orientation, resizing masks were not able to achieve the look I wanted so I implemented the
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
method with an if and else statement, the "if" uses CGRectMakes to draw all of the elements where they should go in landscape layout, and the "else" redraws them back to their original places when changed back to portrait landscape. This all works very nicely. I remembered that we had to be able to handle the double high status bar, so I simulated it to see what it would do to my app. When I am on the home screen and toggle it on and off, the autoresizing of the items(which are set to adjust according to the top of the view) work nicely, by slightly squishing everything down a bit, and not hiding anything. I can toggle it off and on with no problems.
Now here's the problem:
When I have the double high status bar toggled on while on a different screen, then go back to my home screen, the resizing doesn't happen, and it redraws my screen full size according to the coordinates and sizes I have in the method I mentioned earlier, so the settings and info button are drawn halfway off the bottom of the screen. Same happens when switching from landscape back to portrait on the homescreen with the double high status bar already on.
Similarly, I have a map between a nav and tab bar on another page. When already on the page, and toggling it on and off, everything resizes nicely(the frame of the map changes height and the nav bar moves down). But again, I have a problem when switching to that screen from a different screen or from the landscape orientation, because instead of autoresizing appropriately, the map view and nav bar get pushed down behind the tab bar partially, obscuring the google trademark which is grounds for app rejection.
Sorry for the longwindedness, but I wanted to clearly describe what circumstances cause this problem. Any ideas would be greatly appreciated as I don't really have any idea how to approach this.
I've been trying to track down this problem myself. I think this happens because the autoresizing mask is only used when views are resized, and not when a new view is added to the scene.
For me, I wanted a settings view loaded from a nib and added on top of everything else. If the double-height bar was in effect when the view was added it would run off the bottom of the screen. To fix it you have to set the size and position of the view yourself when you load it. This is the code behind my working 'goto settings' button:
- (IBAction) settingsPressed:(id)_sender
{
NSArray* a = [[NSBundle mainBundle] loadNibNamed:#"SettingsView" owner:self options:nil];
SettingsView* settings = [a objectAtIndex:0];
settings.frame = self.view.bounds;
[[self view] addSubview:settings];
}
The important line being:
settings.frame = self.view.bounds;
Which, it would appear, classifies as a 'resize' and so the resizing-mask rules apply. I later added animations for the transition and it continues to work just fine.
Note: This method was in a View Controller.

Increasing width of UISearchDisplayController PopOver Results

I have an iPad app that has a UISearchBar in its navigation bar. When I enter text in the search bar the results are automatically displayed in a UIPopOverController. That's great except the popover's default size is not wide enough for my needs. Is there a way to set its width?
Apple has done this themselves with Safari's search bar. The popover that displays search results is a good bit wider than the default and they have removed the "Results" title from the popover.
You'd need to set the contentSizeForViewInPopover property of the UIViewController that's being displayed in the popover. I'm not sure how you get to that if it's all automagically happening behind the scenes.

UIToolbar above UIWebView inside UIScrollView

I'd like to display a toolbar above a UIWebView but hide the toolbar until the person "pulls it down".
The same functionality can be seen in Safari on the iPhone. When the page loads, the toolbar containing the address is hidden. You must pull it down. In Safari it's possible to scroll up and eventually see the toolbar or scroll down through the page contents.
I've tried placing a UIToolbar and UIWebView inside a UIScrollView but it didn't work.
I've tried setting the UIScrollView to the size of the toolbar and webview combined, but that didn't work.
- (void)viewDidLoad{
CGSize size = CGSizeMake(webView.frame.size.width,
toolBar.frame.size.height + webView.frame.size.height);
[scrollView setContentSize:size];
}
How should I go about doing this?
EDIT
Anyone looking at this should consider that the question and accepted answer are both old and that the API might have changed to allow this.
The UIWebView is itself a UIScrollView so it's not going to work. I'm not sure how Apple does it, but one way to do it, if you have control over the content of the web view, is to write some HTML and CSS that replicates that address bar.