Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Objective-C and Swift
  4. UIWebView Scroll delegate

UIWebView Scroll delegate

Scheduled Pinned Locked Moved Objective-C and Swift
comtutorialquestion
3 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Erdinc27
    wrote on last edited by
    #1

    hey all. i have an UIWebView(tarayici in my situation) in view controller. it works fine when its scroll view delegate is not assigned to view controller. but i need to know when it is scrolled that is why i wrote this code.

    self.tarayici.scrollView.delegate = self;

    but when i write this down then webview acts so weird. for example after this code when i want to scroll then it scrolls only once if i make 3 or 4 attempts. so how can make it work more efficient with that code ?

    vemedya.com

    D 1 Reply Last reply
    0
    • E Erdinc27

      hey all. i have an UIWebView(tarayici in my situation) in view controller. it works fine when its scroll view delegate is not assigned to view controller. but i need to know when it is scrolled that is why i wrote this code.

      self.tarayici.scrollView.delegate = self;

      but when i write this down then webview acts so weird. for example after this code when i want to scroll then it scrolls only once if i make 3 or 4 attempts. so how can make it work more efficient with that code ?

      vemedya.com

      D Offline
      D Offline
      Dennis E White
      wrote on last edited by
      #2

      Before you added your UIWebView did you set the user interaction??

      webView.userInteraction = YES;
      
      // down here is where you add it as a child
      
      E 1 Reply Last reply
      0
      • D Dennis E White

        Before you added your UIWebView did you set the user interaction??

        webView.userInteraction = YES;
        
        // down here is where you add it as a child
        
        E Offline
        E Offline
        Erdinc27
        wrote on last edited by
        #3

        i think i found the solution. The commented UIview animation block locked the main thread i think that is why Scroll View couldnt response to the new touches. but with this new animation block it works well.

        - (void) scrollViewDidScroll:(UIScrollView *)scrollView
        {

        if (self.lastContentOffset > scrollView.contentOffset.y)
        {
            if (self.altView.frame.size.height + self.altView.frame.origin.y > self.screenHeight)
            {
        

        // [UIView animateWithDuration:0.5f animations:^{
        // self.altView.frame = CGRectMake(0, self.altView.frame.origin.y-1, 320, 48);
        // self.tarayici.frame = CGRectMake(0, self.tarayici.frame.origin.y, 320, self.tarayici.frame.size.height-1);
        // }];

                \[UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
                    self.altView.frame = CGRectMake(0, self.altView.frame.origin.y-1, 320, 48);
                    self.tarayici.frame = CGRectMake(0, self.tarayici.frame.origin.y, 320, self.tarayici.frame.size.height-1);
                } completion:^(BOOL finished) {
                    
                }\];
            }
            
        }
        else if (self.lastContentOffset < scrollView.contentOffset.y)
        {
            if (self.altView.frame.origin.y < self.screenHeight)
            {
        

        // [UIView animateWithDuration:0.5f animations:^{
        // self.altView.frame = CGRectMake(0, self.altView.frame.origin.y + 1, 320, 48);
        // self.tarayici.frame = CGRectMake(0, self.tarayici.frame.origin.y, 320, self.tarayici.frame.size.height+1);
        // }];
        [UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
        self.altView.frame = CGRectMake(0, self.altView.frame.origin.y + 1, 320, 48);
        self.tarayici.frame = CGRectMake(0, self.tarayici.frame.origin.y, 320, self.tarayici.frame.size.height+1);
        } completion:^(BOOL finished) {

                }\];
            }
        }
        
        self.lastContentOffset = scrollView.contentOffset.y;
        

        }

        vemedya.com

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups