views:

239

answers:

1

Hi

I am new to iphone development. In my app, i am using number of viewControllers, web view, Tool bar, Tab Bar and so on. Here, i want to achieve orientation(portrait or landscape or vice versa) corresponding device view in all the web views. I could achieve orientation in all web views except those web views are coming under the tab bar controller web view(it may be an one of tab bar view controller or sub view of tab bar controller view).

Here i adding web view by using below code,

  contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
  contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |                  UIViewAutoresizingFlexibleHeight);
  self.view = contentView;
  self.view.autoresizesSubviews = YES;


  CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
  webFrame.origin.y -= 20.0;

  webView1 = [[UIWebView alloc] initWithFrame:webFrame];

  [contentView addSubview:webView1]; 

and using below methods for achieving orientation,

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation 
 {

  return YES;
 }


 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
     {
           if(fromInterfaceOrientation == UIInterfaceOrientationPortrait){
           [webView1 stringByEvaluatingJavaScriptFromString:@"rotate(0)"];

     }

else {

   [webView1 stringByEvaluatingJavaScriptFromString:@"rotate(1)"];
 }

}

please any one give soln!

+1  A: 

Ok lets try this:

Step 1: Crate a custom class for TabBarController class as:

@interface CustomTabBarController : UITabBarController {

}

@end

In CustomTabBarController.m write

`#import "CustomTabBarController.h"

@implementation CustomTabBarController

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    // Always returning YES means the view will rotate to accomodate any orientation.

    return YES;

}

@end

Step 2: On appDelegate write this:

Change UITabBarController "CustomTabBarController" and change it class reference in Interface builder to CustomTabBarController

iPhoneDev