【问题标题】:Enable Orientation in UIWebview when Evaluating Javascript评估 Javascript 时在 UIWebview 中启用方向
【发布时间】:2012-03-03 21:02:14
【问题描述】:

当我开始评估 javascript 时,就像用户选择文本时一样,突出显示选定的文本。对于这种情况,我无法在 iPad 中继续使用设备方向并停止方向,并且在 javascript 完全执行之前它不会处于活动状态。

有什么方法可以在不影响uiwebview方向的情况下处理uiwebview中javascript的评估。

【问题讨论】:

    标签: javascript ipad uiwebview uiinterfaceorientation


    【解决方案1】:

    当然。 当您启动 javascript 时,您可以设置一个布尔变量并使用 UIViewController 的当前方向设置一个变量(您的 UIViewController 实例中的两个变量), 然后在你的 UIViewController 中你必须实现这个方法:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        return YES;
    }
    

    当用户旋转设备时,它会告诉 iPhone 是否可以旋转您的应用程序。

    所以,当你的 javascript 启动时:

    // BOOL stopRotation; // 在 yourViewController.h 中声明 停止旋转 = 真; // UIInterfaceOrientation* currentOrientationFrozen; // 在 yourViewController.h 中声明 currentOrientationFrozen = self.interfaceOrientation;

    和:

        - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
        {
            if (stopRotation){
                 if (interfaceOrientation == currentOrientationFrozen) {
                     return YES;
                 } else {
                     return NO;
                 }
            } 
            return YES;
    
        }
    

    然后,当您的 javaScript 停止时,恢复您的 BOOL 和 currentOrientationFrozen:

    stopRotation = FALSE;
    currentOrientationFrozen = nil;
    

    【讨论】:

      猜你喜欢
      • 2012-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多