【问题标题】:Weird thing: Cannot change UIWebView.origin.x in scrollViewDidEndDecelerating奇怪的事情:无法在 scrollViewDidEndDecelerating 中更改 UIWebView.origin.x
【发布时间】:2016-01-16 17:20:29
【问题描述】:

我正在研究 UIScrollView 中的无限循环 UIWebView,我试图用另一个替换 webview,但失败了。 currWebView.frame.origin.x不能在scrollViewDidEndDecelerating中修改。

func scrollViewDidEndDecelerating(scrollView: UIScrollView) {

    if endDragOffset > 0 {
        // moving forward, get next
        if(scrollView.contentOffset.x > mainScrollView!.frame.size.width) {
            prevWebView = currWebView // get the content of the next one
            currWebView = nextWebView

            // set back the position
            prevWebView.frame.origin.x = 0
            currWebView.frame.origin.x = 320
            nextWebView.frame.origin.x = 640

            var theNext = getNext(nextVolume, theChapter: nextChapter)
            nextVolume = theNext["volume"]!
            nextChapter = theNext["chapter"]!
            nextChapterArr = getLection(nextVolume, theChapter: nextChapter)
            loadPage(nextVolume, theChapter: nextChapter, chapterArr: nextChapterArr, onPage: 2)

            print(currWebView.frame.origin.x) // got 640

            currWebView.frame.origin.x = 320
            print(currWebView.frame.origin.x) // still got 640
        }

        // moving backward, get previous
        if(scrollView.contentOffset.x < mainScrollView!.frame.size.width) {
            //.........
        }

还有其他关于在 UISCrollView 中制作无限 webview 的建议吗?

【问题讨论】:

    标签: ios swift uiscrollview uiwebview infinite


    【解决方案1】:

    使用以下代码可以解决问题

    let frame = nextWebView.frame
    nextWebView.frame = currWebView.frame
    currWebView.frame = prevWebView.frame
    prevWebView.frame = frame
    

    【讨论】:

      猜你喜欢
      • 2017-10-02
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      相关资源
      最近更新 更多