UIWebView redraw after gesture handling
- Get link
- X
- Other Apps
i struggling problem long time, grateful if told me helpful that. bascially, have uiview 3 uiwebviews inside. 1 webview visible: image :
and! want change these webviews, loaded consecutive pages, animation. when made gesture left, webviews moving towards left, , 1 on far left should return initial position on right. maybe image make clear:
after return position near right should loaded next page in array.
where's problem?
when make gesture on uiview (this area dots) - webviews loading fine. when click neighbour dot, webviews animating , loaded right website. ok.
but!
making gesture inside webview. animation done, starting load new websites, but... in our example - after animation, , loading, going right again, see website4. webview having website1, after being loaded website4 (webviewdidfinishload) showing old content! (so it's showing page1, having page4. not always, sometimes... )
when touch it, , scroll little down it's showing right content (???). tried setneedsdisplay on this, triggering hidden = yes/no, without effects.
when reloading webview after sending load request it's showing white,empty area , need scroll down , few times make things better.
should do? connected multi threading, animation, wrong gesture used? should show other parts of code? ideas... here's code:
code:
code:-(void) initgestures { uiswipegesturerecognizer *swiperight = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handlepangesture:)]; swiperight.direction = uiswipegesturerecognizerdirectionright; // swiperight.numberoftouchesrequired = 2; swiperight.delegate = self; [self.mainwidgetwithdotsview addgesturerecognizer:swiperight]; uiswipegesturerecognizer *swipeleft = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handlepangesture:)]; swipeleft.direction = uiswipegesturerecognizerdirectionleft; // swipeleft.numberoftouchesrequired = 2; swipeleft.delegate = self; [self.mainwidgetwithdotsview addgesturerecognizer:swipeleft]; } - (void)slidetocurrentpage { int page = slider.currentpage; nslog(@"slide current page"); //int page = dots.currentpage; int trigger = 1; // forward if (page < mainwidgetmanager.currentpane ) trigger = -1; // backward mainwidgetmanager.currentpane = page; float leftw = leftwebview.layer.position.x; float centerw = webview.layer.position.x; float rightw = rightwebview.layer.position.x; [uiview animatewithduration:animation_duration delay:0 options: uiviewanimationoptioncurveeaseout animations:^{ cgrect rc = mainwidgetview.frame; float w = rc.size.width; float h = rc.size.height; switch (page) { default: leftwebview.layer.position = cgpointmake(leftw-(trigger)*w, h/2); webview.layer.position = cgpointmake(centerw-(trigger)*w, h/2); rightwebview.layer.position = cgpointmake(rightw-(trigger)*w, h/2); break; } } completion:^(bool finished){ [self swipeend:finished direction:trigger]; }]; } -(void) swipeend:(bool)finished direction:(int)dir { (int = 0 ; < 3 ; i++ ) { if (positionofwebviews[i] == center) { contents[i] = currentpane; } if (positionofwebviews[i] == far_left && dir == 1) { nslog(@"manager: left goes right (from %d)", far_left); [self movewebview:mainwebviews[i] topos:near_right]; if (currentpane != widgetsloaded-1 && contents[i] != currentpane+1) { //[mainwebviews[i] stoploading]; contents[i] = currentpane+1; nslog(@"manager: , it's loaded %d",currentpane+1); [self loadtowebview:mainwebviews[i] subwidget:currentpane+1]; } } else if ( positionofwebviews[i] == far_right && dir == -1) { nslog(@"right (%d) goes left", i); [self movewebview:mainwebviews[i] topos:near_left]; if (currentpane != 0 && contents[i] != currentpane -1) { contents[i] = currentpane - 1; nslog(@"manager: , it's loaded %d",currentpane-1); [self loadtowebview:mainwebviews[i] subwidget:currentpane-1]; } } } } -(void)loadtowebview:(uiwebview *)wv subwidget:(int)i { subwidget *tmp = [history objectatindex:i]; nsstring *a = [nsstring stringwithstring:tmp.name]; [wv stoploading]; // [wv loadhtmlstring:a baseurl:nil]; <--- no difference [wv loadrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:a]]]; // [wv reload]; } - (ibaction)handlepangesture:(uiswipegesturerecognizer *)sender { nslog(@"gesture"); if (sender.direction == uiswipegesturerecognizerdirectionleft) { //[mainwidgetmanager getcenterwebview].userinteractionenabled = no; nslog(@"left"); if (slider.currentpage != slider.numberofpages-1) { [slider setcurrentpage:slider.currentpage+1 animated:yes]; [slider sendactionsforcontrolevents:uicontroleventvaluechanged]; } } else if (sender.direction == uiswipegesturerecognizerdirectionright) { // [mainwidgetmanager getcenterwebview].userinteractionenabled = no; nslog(@"right"); if (slider.currentpage > 0) { [slider setcurrentpage:slider.currentpage-1 animated:yes]; [slider sendactionsforcontrolevents:uicontroleventvaluechanged]; } } } - (void)onpagechanged:(id)sender { if ( abs( slider.currentpage - mainwidgetmanager.currentpane ) > 1 ) { nslog(@"long jump"); [self jumptopage:slider.currentpage]; } else { if (mainwidgetmanager.currentpane != slider.currentpage) [self slidetocurrentpage:no dir:no]; } }
solution: using new uiwebview every time want load offscreen.
Forums iPhone, iPad, and iPod Touch iOS Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
- Get link
- X
- Other Apps
Comments
Post a Comment