ScrollView contentSize Larger than Bounds, Yet No Scrolling

dyllandry

I have a scrollView containing a single image. The image's bounds are greater than the scrollView's frame. I have set the scrollView's contentSize to be equal to the image's bounds. Yet no scrolling. I have no idea what could be causing this.

 override func viewDidLoad() {
        super.viewDidLoad()
        var matches = SortThread.getSortThread().retrieveMatches()

        scrollView.frame = CGRectMake(0, navigationController!.navigationBar.frame.height - 20, UIScreen.mainScreen().bounds.width, view.bounds.height - (navigationController!.navigationBar.frame.height - 20))

        var imageName = String()
        imageName = matches[0].pictures![0]
        var parsedImageName = imageName.componentsSeparatedByString(".") as [String]
        var newImageName: String = parsedImageName[0] as String
        let path = NSBundle.mainBundle().pathForResource("MVLMP Images (Resized)/" + newImageName, ofType: "jpg")
        var image = UIImage()
        image = UIImage(contentsOfFile: path!)!
        var imageView = UIImageView(image: image)

        var ratio: CGFloat = image.size.width/image.size.height
        var screenHeight: CGFloat = UIScreen.mainScreen().bounds.height - navigationController!.navigationBar.frame.height - 20

        if(ratio > 1){

            imageView.frame = CGRectMake(0, 0, ((scrollView.bounds.width)/7) * 6, 0)
            imageView.frame = CGRectMake(0, 0, imageView.frame.width, imageView.frame.width * ratio)

        } else {

            imageView.frame =  CGRectMake(0, 0, 0, (screenHeight/9)*8)

            imageView.frame = CGRectMake(0, 0, imageView.frame.height * ratio, imageView.frame.height)

        }

        scrollView.addSubview(imageView)
        scrollView.contentSize.width = imageView.frame.width
        scrollView.contentSize.height = imageView.frame.height

    }

}

I've printed out the scrollView.contentSize.width and the scrollView.bounds.width and the content width is in fact greater than the bounds width by about 40.

dyllandry

As Muc Dong commented, I was adding the width of the images to the scrollView's contentSize.width. This was not necessarily the correct thing to do as in my case there is some margin between the images that I was not accounting for. This margin should of been included in the additions to to scrollView.contentSize.width.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Scrollview will not scroll even with larger contentsize

From Dev

Scrollview ContentSize

From Dev

Dynamic scrollView contentSize autoLayoutConstraints swift

From Dev

UIScrollView not scrolling regardless of large contentSize

From Dev

Android textview's view bounds are much larger than content, how to remove it?

From Dev

iOS autolayout vs ScrollView : Contentsize issue

From Dev

-[UIScrollView zoomToRect:animated:] weird behavior when contentSize < bounds.size

From Dev

-[UIScrollView zoomToRect:animated:] weird behavior when contentSize < bounds.size

From Dev

Android: ScrollView is not scrolling

From Dev

conflict scrolling scrollview and tableview

From Dev

scrolling ListView within ScrollView

From Dev

CollapsingToolbarLayout not scrolling with scrollview

From Dev

Kivy ScrollView - Not Scrolling

From Dev

LinearLayout not scrolling with ScrollView

From Dev

Disable scrolling on a Scrollview

From Dev

Scrolling within a ScrollView

From Dev

ScrollView is not Scrolling completely in android

From Dev

ScrollView Not Scrolling to The End of The View

From Dev

Android ScrollView Not Scrolling Correctly

From Dev

scrollview inside a fragment is not scrolling

From Dev

Scrolling a ScrollView to a specific id

From Dev

ScrollView is not Scrolling completely in android

From Dev

Scrolling within a ScrollView

From Dev

Android Scrolling of a ScrollView

From Dev

Disable scrolling on a Scrollview

From Dev

TouchImageView is not scrolling inside ScrollView

From Dev

Swift ScrollView - contentSize can't take a variable Int

From Dev

Why does changing contentsize value of scrollView doesnot effect the result

From Dev

LinearLayout larger than screen

Related Related

HotTag

Archive