【问题标题】:Orientation issues with Tab Bar Controller In WebViewWebView 中标签栏控制器的方向问题
【发布时间】:2012-08-26 15:31:20
【问题描述】:

我是 iphone 开发新手。在我的应用程序中,我使用了许多 viewController、Web 视图、工具栏、标签栏等。在这里,我想在所有网络视图中实现方向(纵向或横向,反之亦然)相应的设备视图。我可以在所有 Web 视图中实现方向,除了那些 Web 视图位于标签栏控制器 Web 视图下(它可能是标签栏视图控制器或标签栏控制器视图的子视图之一)。

这里我使用下面的代码添加网页视图,

  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]; 

并使用以下方法来实现定位,

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation 
 {

  return YES;
 }


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

     }

否则 {

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

}

请任何人提供解决方案!

【问题讨论】:

    标签: iphone uiwebview orientation


    【解决方案1】:

    好的,让我们试试这个:

    第 1 步:为 TabBarController 类创建一个自定义类:

    @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
    

    第 2 步:在 appDelegate 上写下:

    更改 UITabBarController "CustomTabBarController" 并将 Interface builder 中的类引用更改为 CustomTabBarController

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 2018-02-24
      • 1970-01-01
      • 2012-04-24
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      相关资源
      最近更新 更多