ios - 奇怪的事情: Cannot change UIWebView. origin.x在scrollViewDidEndDecelerating

标签 ios swift uiscrollview uiwebview infinite

我正在挖掘 UIScrollView 中的无限循环 UIWebView,我尝试用另一个 webview 替换 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 的任何其他建议吗?

最佳答案

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

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

关于ios - 奇怪的事情: Cannot change UIWebView. origin.x在scrollViewDidEndDecelerating,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33196161/

相关文章:

UIView 中的 iOS UIScrollView

ios - 如何通过 NSOperationQueue 从多个 url 下载多个文件

iOS ScrollView 边界不等于 super View 边界

ios - 带有 brozot/Laravel-FCM 的 laravel fcm 推送通知不适用于 ios,但在 android 上运行良好

parsing - 跳出深度递归函数调用

swift - 如何在 Swift 中将继承应用于泛型

ios - KeyboardWillShow 中设置的执行顺序错误

ios - 如何使 ScrollView 宽度 = 设备屏幕宽度?

ios - 如何将 ImageSliderViewController 转换为 Swift 2

ios - UIScrollView 缩放不适用于自动布局