Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll View add to Table View Cell #8

Open
PaingSoe93 opened this issue Jun 7, 2016 · 6 comments
Open

Scroll View add to Table View Cell #8

PaingSoe93 opened this issue Jun 7, 2016 · 6 comments

Comments

@PaingSoe93
Copy link

PaingSoe93 commented Jun 7, 2016

Firstly i add the horizontalScrollView to UIView seen no problem. But Added to table view cell does not show the last items and scroll view width is beyond the container view.

screen shot 2016-06-07 at 11 08 35 pm

here is my code...

     let horizontalScrollView = ASHorizontalScrollView(frame:CGRectMake(0, 30, containerView.frame.size.width , 150))
    horizontalScrollView.backgroundColor = UIColor.blueColor() //add color for testing
    horizontalScrollView.leftMarginPx = 30
    horizontalScrollView.miniMarginPxBetweenItems = 15
    horizontalScrollView.miniAppearPxOfLastItem = containerView.frame.size.width-(200+30+50)
    horizontalScrollView.uniformItemSize = CGSizeMake(200, 150)
    //This must be called after changing any size or margin property of this class to get acurrate margin
    horizontalScrollView.setItemsMarginOnce()
    for nub in 1...7{
        if let addView = NSBundle.mainBundle().loadNibNamed("ScrollViewController", owner: ScrollViewController(), options: nil)[0] as? ScrollView{
            addView.titleLable.text = "\(nub)"
            horizontalScrollView.addItem(addView)
        }   
    }
    containerView.addSubview(horizontalScrollView)
@terenceLuffy
Copy link
Owner

Your horizontalScrollView has a fixed width = containerView.frame.size.width, if you don't have auto layout code to adjust the scrollview and the container view, then it should be fit. As I can imagine, your container view do have auto layout setting on it to resize the width. But the horizontalScrollView is not adjusted correspondingly. If this is the case, I suggest your add constraints to horizontalScrollView too.

Again, your tableview cell width is limited to the table view, but the horizontalScrollView width is not, adjust your horizontalScrollView width correspondingly.

@PaingSoe93
Copy link
Author

I got it. Thanks terenceLuffy 👍

@PaingSoe93
Copy link
Author

PaingSoe93 commented Jun 8, 2016

Set the horizontal scroll view frame to fixed width and adjust with constraints. Its looks fine.But the last items doesn't appear fully. And margin between items is not ok in 4s but fine in 6s.

screen shot 2016-06-08 at 11 53 49 am

here my code...

let horizontalScrollView = ASHorizontalScrollView(frame:CGRectMake(0, 0, 300, 150))
horizontalScrollView.backgroundColor = UIColor.blueColor()
horizontalScrollView.leftMarginPx = 10
horizontalScrollView.miniMarginPxBetweenItems = 15
horizontalScrollView.miniAppearPxOfLastItem = 30
horizontalScrollView.uniformItemSize = CGSizeMake(200, 150)
//This must be called after changing any size or margin property of this class to get acurrate margin
horizontalScrollView.setItemsMarginOnce()
for nub in 1...7{
if let addView = NSBundle.mainBundle().loadNibNamed("ScrollViewController", owner: ScrollViewController(), options: nil)[0] as? ScrollView{
addView.titleLable.text = "(nub)"
horizontalScrollView.addItem(addView)
}
}
containerView.addSubview(horizontalScrollView)
horizontalScrollView.translatesAutoresizingMaskIntoConstraints = false
let viewsDictionary = ["horizontalScrollView":horizontalScrollView]
let containerView_H = NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[horizontalScrollView]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewsDictionary)
let containerView_V = NSLayoutConstraint.constraintsWithVisualFormat("V:|-10-[horizontalScrollView]-10-|", options: NSLayoutFormatOptions(rawValue:0), metrics: nil, views: viewsDictionary)
containerView.addConstraints(containerView_H)
containerView.addConstraints(containerView_V)

@terenceLuffy
Copy link
Owner

terenceLuffy commented Jun 8, 2016

Your code seems correct. But you can check on two things to make sure:

  1. Check the content size of scrollview to see if it can hold all your 7 items and the right edge margin after all view showed. If this is the case (probably), maybe refreshSubView is not called when scrollview frame changed, you can try to manually call it to see if there is any difference.
  2. Check the width of your last item to see if it is correct size

The gap differences in 6 and 4s is normal. Because the screen width is different. In 5s and below, it is 320, and 6 is 375, 6 plus is 414. Therefore, you should have different width and gap for different phones.

@PaingSoe93
Copy link
Author

Hi TerenceLuffy. How can i pin the last scroll index in HorizontalScrollView. For example add the horizontalScrollView to TableView. When scroll the tableView the horizontalScrollView index lose and show the first index ever.

@terenceLuffy
Copy link
Owner

I guess you reuse the table view cell which contains the scroll view? I suggest you don't do that because you probably won't have same items for all scroll views? If you don't reuse the cell for other cells, it won't move the scrollview's index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants