开发者

Orientation issues with Tab Bar Controller In WebView

开发者 https://www.devze.com 2022-12-21 12:45 出处:网络
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) corresp

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) shouldAutorotateToInterfaceOr开发者_Python百科ientation: (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!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消