views:

32

answers:

0

Hi, my problem seems to be difficult to describe. But anyways I´ll give it a try ;)

OK, we have an HomeScreen in our universalapp as the first View (TTLauncherView from Three20). here we have a Banner at the bottom which will be later a place for adds by a local sponsor. This Banner is actually an UIButton which a ModalViewTransition. In this ModalView i added an UIWebView with a UINavigationBar at the top and a UIToolbar on the Bottom.

here is the implementation Code from the WebViewController.m for the specified UI Items

// Setting the Web View
webView = [ [ UIWebView alloc ] 
           initWithFrame:CGRectMake(0.0f, 
                                    44.0f, 
                                    [ [ UIScreen mainScreen ] bounds ].size.width, 
                                    [ [ UIScreen mainScreen ] bounds ].size.height - 44.0f - 52) ];
webView.autoresizesSubviews = YES;
webView.autoresizingMask    = (UIViewAutoresizingFlexibleHeight | 
                               UIViewAutoresizingFlexibleWidth);
webView.backgroundColor     = [ UIColor grayColor ];

//set the web view delegates for the web view to be itself
[ webView setDelegate:self ];

// Enabling Multi Touch Gestures for Pinch and Zoom
webView.scalesPageToFit             = YES;
webView.multipleTouchEnabled        = YES; 
webView.userInteractionEnabled      = YES;

// Create an URL object.
// NSURL *url = [ NSURL URLWithString:self.webViewURL ];
NSURL *url = [ NSURL URLWithString:@"http://www.spiegel.de" ];

// URL Request Object
NSURLRequest *requestObj = [ NSURLRequest requestWithURL:url ];

// load the URL into the web view.
[ webView loadRequest:requestObj ];

// add the web view to the content view
[ self.view addSubview:webView ];
[ webView release ];

// Setting Navigation Bar
CGRect navBarRect = CGRectMake(0.0f, 
                               0.0f, 
                               [ [ UIScreen mainScreen] bounds ].size.width, 
                               44.0f);

  navBar = [ [ UINavigationBar alloc ] initWithFrame: CGRectMake(navBarRect.origin.x, 
                                                               navBarRect.origin.y, 
                                                               navBarRect.size.width, 
                                                               44.0f)];

  navBar.autoresizesSubviews = YES;
  navBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[ navBar setDelegate: self.view ];
[ self.view addSubview: navBar ];
[ navBar release ];


[ navBar setDelegate: self ];

After that I added 2 Buttons (a Home Button for dismissing the ModalViewControler and a reloadButton for the WebView ) and a Title in the Navbar. First Problem was that I tried to add these things in the "normal" way. means: as UIBarButtonItems and so on But that was not working. Didnt see anything of UIBarButtonItems and also didnt see any title.

Next I tried to add them as normal UIButtons and the title as Normal Label and added them as subview to the navBar. It works! After that I added a third Button which is Blank and an UIActivityIndicator. Because i want to replace the reloadButton with theBlank Button while the WebView is Loading and place the ActivitIndicator above the blank Button so itlooks like the Button has an own Spinner in it.

see the following code:

// Setting Home Button ////////////////////////////////////////////////////////////////////////

homeButton = [[UIButton alloc] initWithFrame:CGRectMake(10.0f, 7.0f, 36.0f, 30.0f)];

[homeButton setBackgroundImage:[UIImage imageNamed:@"homeButton.png"] 
                      forState:UIControlStateNormal];

homeButton.opaque = YES; // explicitly opaque for performance !!!

[homeButton addTarget:self 
               action:@selector(dismissWebView:) 
     forControlEvents:UIControlEventTouchUpInside];

[navBar addSubview:homeButton];

[homeButton release];



// Setting Reload Button //////////////////////////////////////////////////////////////////////

reloadButton = [ [ UIButton alloc ] initWithFrame:CGRectMake 
                (                                 
               [ [ UIScreen mainScreen] bounds ].size.width - 46.0f, 
                   7.0f, 
                   36.0f, 
                   30.0f 
                 ) ];

[reloadButton setBackgroundImage:[UIImage imageNamed:@"reloadButton.png"] 
                        forState:UIControlStateNormal];

reloadButton.opaque = YES; // explicitly opaque for performance !!!
reloadButton.autoresizesSubviews = YES;
reloadButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | 
                                UIViewAutoresizingFlexibleBottomMargin;

[reloadButton addTarget:self 
                 action:@selector(reloadWebView:) 
       forControlEvents:UIControlEventTouchUpInside];

[navBar addSubview:reloadButton];

// Setting Blank Button //////////////////////////////////////////////////////////////////////

// CGRect blankButtonRect = CGRectMake([ navBar frame ].size.width - 46, 7.0f, 36.0f, 30.0f);
blankButton = [[UIButton alloc] initWithFrame:CGRectMake(                                 
                                                         [ [ UIScreen mainScreen] bounds ].size.width - 46.0f, 
                                                         7.0f, 
                                                         36.0f, 
                                                         30.0f 
                                                         ) ];


[blankButton setBackgroundImage:[UIImage imageNamed:@"blankButton.png"] forState:UIControlStateNormal];
blankButton.opaque = YES; // explicitly opaque for performance !!!
blankButton.autoresizesSubviews = YES;
blankButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;


// Setting TitleString
adClientTitleString = [ [ NSString alloc] initWithString:@"TZ-Online" ];

// Setting Title as Label 

adClientTitle = [ [ UILabel alloc ] 
                 initWithFrame: CGRectMake (0.0f, 
                                            0.0f, 
                                            [ [ UIScreen mainScreen ] bounds ].size.width,
                                            44.0f) ];

  adClientTitle.text            =   adClientTitleString;
  adClientTitle.font            =   [ UIFont boldSystemFontOfSize:21 ];
  adClientTitle.shadowColor     =   [ UIColor darkGrayColor ];
  adClientTitle.shadowOffset    =   CGSizeMake(0.0f, -1.0f);

[ adClientTitle setBackgroundColor: [ UIColor clearColor ] ];
[ adClientTitle setTextAlignment:     UITextAlignmentCenter ];
[ adClientTitle setTextColor:       [ UIColor whiteColor ] ];

  adClientTitle.autoresizingMask    = UIViewAutoresizingFlexibleWidth;
  adClientTitle.autoresizesSubviews = YES;

[ navBar addSubview:adClientTitle ];

After that i made the WebView Load Methods working:

- (void)webViewDidStartLoad:(UIWebView *)webView {

[ reloadButton      removeFromSuperview ];
[ navBar            addSubview:blankButton ];
[ navBar            addSubview:activityIndicator ];
[ activityIndicator startAnimating ];

}

- (void)webViewDidFinishLoad:webView {

// Enable or disable back
[ backwardButton         setEnabled:[webView canGoBack]];

// Enable or disable forward
[ forwardButton         setEnabled:[webView canGoForward]];
[ blankButton           removeFromSuperview ];
[ navBar                addSubview:reloadButton];
[ activityIndicator     stopAnimating ];

It is all working the Indicator is shown in the right moment and s disappearing when the webView finishes to load. But what happens in the Interface is this: http://www.youtube.com/watch?v=XSA51RIfvBM

The Buttons are jumping when in landscape mode in a very inconsistend manner I think. sometimes its the reload button sometimes its the blank button. also on the device (3G and iPad) it was the same. Thank you for helping. And sorry for this long Post.