logo
down
shadow

How to know, how much I scrolled in a UIScrollview?


How to know, how much I scrolled in a UIScrollview?

By : user3851752
Date : October 15 2020, 11:12 PM
should help you out UIScrollViewDelegate's - (void)scrollViewDidScroll:(UIScrollView *)scrollView combined with [scrollView contentOffset] and [scrollView setContentOffset:] should handle what you've described.
Please edit and sample code for what you've tried already.
code :


Share : facebook icon twitter icon
UIScrollView- How far is it scrolled?

UIScrollView- How far is it scrolled?


By : Dana Comer Anderson
Date : March 29 2020, 07:55 AM
Any of those help your scroll view's delegate should repsond to scrollViewDidEndScrollingAnimation: and use that to check where you are
code :
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
  // Get some details about the view
  CGSize size = [scrollView frame].size;
  CGPoint offset = [scrollView contentOffset];
  CGSize contentSize = [scrollView contentSize];

  // Are we at the bottom?
  if (-offset.y + size.height <= contentSize.height)
    NSLog(@"bottom");
  else
    NSLog(@"not bottom");
}
UIScrollView jumping when scrolled

UIScrollView jumping when scrolled


By : John
Date : March 29 2020, 07:55 AM
around this issue i think you should set the frame and also the contentSize of the scrollView
Stop an animating UIScrollView when another UIScrollView is scrolled

Stop an animating UIScrollView when another UIScrollView is scrolled


By : Chut Aroon
Date : March 29 2020, 07:55 AM
it helps some times Well... I found a work around. I used a variable viewOpenCounter to keep track if another scroll view is opened, and if it is, then close the currently animating scroll view after it finishes animating. Not sure if this is efficient.
code :
func scrollViewDidScroll(scrollView: UIScrollView) {

    scrollView.bounces = scrollView.contentOffset.x > 20

    if scrollView.contentOffset.x < self.lastContentOffset && scrollView.contentOffset.x < 70 {
        isOpening = false
    }
    else if scrollView.contentOffset.x > 5 {
        isOpening = true
        viewOpenCounter = true
    }
    self.lastContentOffset = scrollView.contentOffset.x
}

func scrollViewWillBeginDragging(scrollView: UIScrollView) {
    if !viewOpenCounter {
        for eachScrollView in taskArrayScrollView {
            if  eachScrollView != scrollView {
                UIView.animateWithDuration(0.2,
                    delay: 0.5,
                    options: .CurveEaseIn ,
                    animations: { eachScrollView.contentOffset.x = 0 },
                    completion: nil
                )}
        }
    }
}
 func scrollViewDidEndDragging(scrollViewa: UIScrollView, willDecelerate decelerate: Bool) {

    viewOpenCounter = false

    let intialContentOffset = scrollViewa.contentOffset.x
    var originalContentOffset: CGFloat
    var finalContentOffset: CGFloat
    var minOffset: CGFloat

    if intialContentOffset == boundOfScreen.width{
        return
    }

    if isOpening{
        minOffset = 20.0
        originalContentOffset = 0
        finalContentOffset = 70
    }

    else {
        minOffset = 50.0
        originalContentOffset = 0
        finalContentOffset = 70
    }

    if (!decelerate){
        //println("no dec \(intialContentOffset)")

        if intialContentOffset < minOffset {
            UIView.animateWithDuration(0.2,
                delay: 0.1,
                options: .CurveEaseIn ,
                animations: { scrollViewa.contentOffset.x = originalContentOffset },
                completion: {
                    finished in scrollViewa.userInteractionEnabled = true
                    if self.viewOpenCounter {
                        UIView.animateWithDuration(0.2, animations: {
                            scrollViewa.contentOffset.x = 0
                        },
                            completion: {
                                finished in
                                self.viewOpenCounter = false
                            }
                        )
                    }
                }
            )
        }
        else {
            UIView.animateWithDuration(0.2,
                delay: 0.1,
                options: .CurveEaseIn ,
                animations: { scrollViewa.contentOffset.x = finalContentOffset },
                completion: {
                    finished in scrollViewa.userInteractionEnabled = true
                    if self.viewOpenCounter {
                        UIView.animateWithDuration(0.2, animations: {
                            scrollViewa.contentOffset.x = 0

                        },
                            completion: {
                                finished in
                                self.viewOpenCounter = false
                            }
                        )
                    }
                }
            )
        }
    }
}

 func scrollViewDidEndDecelerating(scrollViewb: UIScrollView) {

    viewOpenCounter = false

    let intialContentOffset = scrollViewb.contentOffset.x
    var originalContentOffset: CGFloat
    var finalContentOffset: CGFloat
    var minOffset: CGFloat
    //println("intialContentOffset: \(intialContentOffset)")

    if isOpening{
        minOffset = 20.0
        originalContentOffset = 0
        finalContentOffset = 70
        //println("dec: opening")
    }

    else {
        minOffset = 50.0
        originalContentOffset = 0
        finalContentOffset = 70
        //println("dec: closing")
    }


    if intialContentOffset < minOffset {
        UIView.animateWithDuration(0.2,
            delay: 0.1,
            options: .CurveEaseIn ,
            animations: {scrollViewb.contentOffset.x = originalContentOffset },
            completion: {
                finished in scrollViewb.userInteractionEnabled = true
                if self.viewOpenCounter {
                    UIView.animateWithDuration(0.2, animations: {
                        scrollViewb.contentOffset.x = 0
                    },
                        completion: {
                            finished in
                            self.viewOpenCounter = false
                        }
                    )
                }
            }
        )
    }
    else {
        UIView.animateWithDuration(0.2,
            delay: 0.1,
            options: .CurveEaseIn ,
            animations: {scrollViewb.contentOffset.x = finalContentOffset },
            completion: {
                finished in scrollViewb.userInteractionEnabled = true
                if self.viewOpenCounter {
                    UIView.animateWithDuration(0.2, animations: {
                        scrollViewb.contentOffset.x = 0
                    },
                        completion: {
                            finished in
                            self.viewOpenCounter = false
                        }
                    )
                }
            }

        )
    }
}
Keep UIScrollView scrolled to bottom

Keep UIScrollView scrolled to bottom


By : Jack Merr
Date : March 29 2020, 07:55 AM
Hope this helps You can achieve this behaviour by using a non-animated version of setContentOffset within the same animation block you use for resizing the UIScrollView — in this case both changes will be animated simultaneously. Something like:
code :
UIView.animateWithDuration(0.5, animations: { () -> Void in

    let delta: CGFloat = 100

    /// Change UIScrollView's height with some delta value, for instance:
    self.scrollView.frame.size.height -= delta

    /// Update content offset with the same delta value:
    self.scrollView.contentOffset.y += delta
})
Check which UIScrollView is being scrolled?

Check which UIScrollView is being scrolled?


By : Jason B.
Date : March 29 2020, 07:55 AM
like below fixes the issue I'm new to iOS development and I don't know how scrollViewDidScroll method works. I'm using the method to connect between UIViewPager(Top Image Slider in the screenshot) and UIPageControl as a tutorial said. But sadly, whenever I scroll UICollectionViews(Shoes in the screenshot) that method is being called and pageControl is effected unnecessarily. It will be great if I could differentiate which view is scrolled(UIScrollView or UICollectionView) inside the scrollViewDidScroll method. , You can check which scrollView is being scrolled like this:
code :
func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if scrollView === yourCollectionView {
        //Do something
    }
    //or you can use this
    if scrollView.isKind(of: UICollectionView.self) {
        //Do something
    }
}
Related Posts Related Posts :
  • UIAccelerometer Detecting angle Problem
  • How should I handle an incoming call when my application is active on the iPhone?
  • Making toolbar hidden
  • How to add a drop shadow to a UIButton?
  • iPhone: install certificate for SSL connection
  • Clickable links in UITableView that open up Safari
  • iPhone - application being ejected
  • How do I turn on Research Assistant in XCODE Version 3.2.1?
  • Programmaticlaly moving rows with animation in UITableView
  • How to get the Device UUID on the Simulator?
  • How to Add a Splash Screen or Initial View to the Xcode iPhone Utility Template
  • How to zoom within distance by giving location?
  • How to use Key Value Coding to Set Property Values in ABPerson
  • ASIHTTPRequest set timeout
  • How to convert xml to sqlite
  • UITableViewCell background size
  • iPhone TabBarController - set selected tab programmatically
  • Objective c - anything like c?
  • Titanium vs The Native Tools
  • How to terminate an iPhone application through a TabBaritem in Interface Builder?
  • How to Display offline map in iphone using Mapkit
  • iPhone UIWebview Loads on Simulator But not on Device
  • Clear button color on text field
  • calling selector with two arguments on NSThread issue
  • Objective-C: Instance Method is Never Called
  • iPhone: How to Get Basic Authentication to HTTPS Web Service Using NSURLCredential
  • How to set the Tab bar item 1 to be selected by default in iphone?
  • Is it possible to insert an animation into an UITabBarController thats shown when switching Views?
  • CAScrollLayer doesn't scroll!
  • sizeWithFont doesn't give correct height for UITextView if there is a long string in the text being wrapped
  • iPhone ABPeoplePickerNavigationController - How to select two single entries of two different multivalue properties of a
  • iphone sdk: application icon not displaying in simulator
  • Which method should use to release an object?
  • UILabel and superscript
  • UIFont crash problem
  • Is there any way to prevent the user from deleting the installed application?
  • How do I import a CSV file into my iPhone application?
  • How to Post attachments to twitter using twitter API
  • CALayer and obtaining currentcontext of its UIView
  • Scrolling don't work in UITextView included in UIImageView
  • Deleting photos from Resource Path
  • Objective-C copy an NSArray properly?
  • Is the APN Device Token unique to each individual app?
  • NSURLCache Problem with cache response
  • iPad viewWillAppear and presentModalViewController problems
  • How to set the position of a sprite within a box2d body?
  • Localization of strings in static lib
  • How to download text file from web on iPhone?
  • Tesseract Example for Iphone
  • How to record speech in iphone?
  • strange multiple files download - NSURLConnection
  • Is there anyway to get javascript error on android or iphone mobile webkit browser?
  • Keeping UINavigationController's navigationBar hidden after UISearchDisplayController selection
  • Hiding a UINavigationController's UIToolbar during viewWillDisappear:
  • how to run application in background in iphone?
  • Some stress tests on my Iphone app
  • I want to know how to sort the dates in objective c?
  • how to hide URL bar in ipod touch
  • ABRecordRef vCard
  • OBJ-C: Getting the minimum/maximum value in a NSMutableArray
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org