更改UIWebview框架会更改iOS9中的scrollView

时间:2015-11-03 19:54:50

标签: ios swift uiwebview

我有UIWebView个嵌入视频作为UIView的附加子视图。整个页面以编程方式完成。我动画了网页视图的框架更改动画,但是一旦我更改框架,它的scrollView就会自动调整大小。

每当我更改webView.scrollView时,如何阻止webView.frame调整大小?

编辑:将webView.frame更改webView.scrollView.contentSize.height更改为webView.frame.height以外的值。为什么呢?

enter image description here enter image description here

我的最小化视图功能是:

func minimizeViewOnPan() {

        self.btnDown.hidden = true
        var trueOffset: CGFloat = self.initialFirstViewFrame.size.height - 95
        var xOffset: CGFloat = self.initialFirstViewFrame.size.width - 165

        viewFrame.size.width = 160
        viewFrame.size.height = 90
        viewFrame.origin.y = trueOffset
        viewFrame.origin.x = xOffset

        UIView.animateWithDuration(0.3, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

            self.viewYouTube.frame = self.viewFrame
            // self.viewYouTube.frame & self.viewFrame on iPhone 6: (210.0, 572.0, 160.0, 90.0)

            // self.webView is a subview of self.viewYouTube
            self.webView.frame = CGRectMake(self.player.frame.origin.x, self.player.frame.origin.x, self.viewFrame.size.width, self.viewFrame.size.height)
            // On iPhone 6: (0.0, 0.0, 160.0, 90.0)


            }) { (finished) -> Void in

                // add tap gesture
                self.tapRecognizer = nil
                if (self.tapRecognizer == nil) {

                    self.tapRecognizer = UITapGestureRecognizer(target: self, action: "expandViewOnTap:")
                    self.tapRecognizer.numberOfTapsRequired = 1
                    self.tapRecognizer.delegate = self
                    self.viewYouTube.addGestureRecognizer(self.tapRecognizer)
                }

                self.isExpandedMode = false
                self.minimizedYouTubeFrame = self.viewYouTube.frame

                if (self.direction != nil) && (self.direction == UIPanGestureRecognizerDirection.Down) {

                    self.onView.bringSubviewToFront(self)
                }
        }

    }

超过一半的视频被截断。所以我的问题是,为什么最小化的视频调整不正确?

1 个答案:

答案 0 :(得分:0)

想出来。我们正在显示一个高度为210的YouTube iFrame。因此,当视图最小化时,我无法调用contentSize,因为它是由JS iFrame控制的。因此,由于视频的高度为210,webview的高度为90,我们使用self.player.scrollView.contentOffset = CGPointMake(0, 60)((210/2) - (90/2)= 60)来偏移视图的高度。