2015-10-17 2 views
0

Используя 3 страницы UIWebView (0,1,2) для имитации бесконечных страниц в UISccrollView, он работает нормально при прокрутке и изменении содержимого.Как загрузить UIWebView в бесконечном UIScrollView без перезагрузки дважды?

Проблема в том, что currWebView снова загружает новый контент из старого содержимого при остановке прокрутки. Как я могу перемещать страницы плавно и показывает currWebView с флэш-памятью?

func loadPage(theVolume:Int, theChapter:Int, chapterArr:NSArray, onPage page: Int) { 

    switch(page) { 
    case 0: 
     prevWebView.loadRequest(webViewRequest); 
     break 
    case 1:    
     // I try to replace the following line with: currWebView = prevWebView, it shows blank 
     currWebView.loadRequest(webViewRequest); 
     break 
    case 2: 
     nextWebView.loadRequest(webViewRequest); 
     break 
    default: 
     break 
    } 
} 


func scrollViewDidEndDecelerating(scrollView: UIScrollView) { 

    // moving forward 
    if(scrollView.contentOffset.x > mainScrollView!.frame.size.width) { 

     prevChapterArr = currChapterArr 
     loadPage(volumeNum, theChapter: chapterNum, chapterArr: prevChapterArr, onPage: 0) 

     var theNext = getNext(volumeNum, theChapter: chapterNum) 
     volumeNum = theNext["volume"]! 
     chapterNum = theNext["chapter"]! 
     currChapterArr = nextChapterArr 
     loadPage(volumeNum, theChapter: chapterNum, chapterArr: currChapterArr, onPage: 1) 

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

    } 

    // moving backward 
    if(scrollView.contentOffset.x < mainScrollView!.frame.size.width) { 
     // similar codes as above 
    } 

    // reset offset to the middle page 
    self.mainScrollView!.scrollRectToVisible(CGRectMake(mainScrollView!.frame.size.width, 0, mainScrollView!.frame.size.width, mainScrollView!.frame.size.height), animated: false) 

} 

ответ

0

Используя следующие коды, чтобы заставить это работать, и вам не нужно запрашивать все веб-просмотры еще раз.

let tmp = prevWebView 
prevWebView = currWebView 
currWebView = nextWebView 
nextWebView = tmp 
nextWebview.loadRequest(webViewRequest) 
Смежные вопросы