I have a UIView which I need to stretch to the width of a UIScrollView. The problem is the next:
I'd need to stretch that UIView (which is EGOTableViewPullRefresh, just a custom UIView). In the view initialization I put [_refreshHeaderView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];. I tried:
-(void)scrollViewDidZoom:(UIScrollView *)scrollView {
NSLog(#"scrollViewDidZoom");
[_refreshHeaderView setFrame:CGRectMake(0.0f, 0.0f - webScroller.bounds.size.height, webScroller.frame.size.width, webScroller.bounds.size.height)];
}
But it just looks as the image. If I enter to a iOS designed page (such as Mobile Google), it looks ok:
How can I do that?
The size.width of a UIScrollView is width of the view on your device, not the width of the contents inside the scroll view (which would be scrollView.contentSize.width).
This means, if "your view" is outside the UIScrollView you do want the scroll view width, but if your view is inside the scroll view you need the content width.
Notice the bottom/Google screenshot you provided. Notice how there is no horizontal scrolling? In this case the scroll view contents size width is the same as the scroll view width so it works perfectly. The upper/stack overflow image does have a horizontal scroll bar though. So the content width of the scroll view is bigger than the scroll view width.
Short answer: Try setting your view to be the scrollView.contentSize.width, not scrollView.frame.size.width
Related
I'm trying to rebuild the twitter post tweet feature as well as the UI. I'm currently at the point that, when I type something long in the UITextView. My selected image that I want to tweet get bounds out of the container view that is in a scrollview.
See this example:
The blue background is the scrollview background and the grey background is the container views background. I can't scroll too.
My UIImageView has initially 0 height and is directly attached to the top of the textview.
I change the height of the UIImageView with their constraint:
// sets the image
let newHeight = self.postedImageView.getImageHeight(forImage: image)
self.postedImageViewHeightConstraint.constant = newHeight
self.view.layoutIfNeeded()
self.postedImageView.showImage(image)
How can I make this the scrollviews contentView height to grow as I type something in the textview so it doesn't get bounds out the view?
These are my constraints:
Update:
With the postedimageviews bottom constraint added to the content views bottom
I have a UIScrollView for which I have a UIView which is the subview of the scroll view , the UIView has a lot of other subviews and I am getting the height for it dynamically after adding the subviews , this is my piece of code to add the view to scroll view
CGRect frameOfView = CGRectMake(0, 0,Get_Bounds.width, globalYPosition);
self.parentProductDetailView = [[UIView alloc]initWithFrame:frameOfView];
I am first initialising the view this way and then after adding all subviews I am doing this,
frameOfView.size.height = globalYPosition;
[self.parentProductDetailView layoutSubviews];
self.parentProductDetailView.frame = frameOfView;
[self.productDetailScrollView addSubview:self.parentProductDetailView];
self.productDetailScrollView.contentSize = CGSizeMake(0, self.parentProductDetailView.frame.size.height *1);
But my scrollview does not scroll properly it either sticks to top or bottom.
Here globalYPosition is the sum of height of all subviews added to parentProductDetailView
The procedure you used seems correct. No matter the subviews your scroll view should scroll properly by simply using a larger content size then its frame size.
The scroll view may stick, snap to some points if paging is enabled which is what is happening in your case. If the content view is larger then 1.5th of the frame size then the scroll view will snap to top/bottom or left/right. If it is smaller then it will only snap to starting position.
This may be very useful for situations like having a side menu that takes a part of a screen but in your case you should simply disable the paging and scrolling should work fine.
I used storyboard with autolayout enable. I put a UIScrollView in storyboard. Then drag a UITableView over the scrollview. I set the table view's width bigger than the scroll view's width. I then set the constraints with the trailing space to scrollview with a negative number and storyboard fill all other constraints without error. The structure look like:
UIView
UIScrollView
UITableView
in code, I set the scroll view content size:
self.scrollView.contentSize = CGSizeMake(500, 400);
the size matches table view's size. But it doesn't work. The table view will not scroll horizontally. What I am doing wrong and how to make a UITableView scroll horizontally. I mean the whole table, not the each cell scroll horizontally. Thanks for your help.
I config scrollView contentSize same as its frame height(I also test <), Why scorll bar still shown, it seems that the scrollview content size is not what I configed in code.
I think you are place scroll view in view with size for Retina 4 inch, and scroll view automaticaly resized.
add line in viewDidLoad method
self.mainScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
or set up right autoresizing mask in IB.
I have got a UIScrollView with a UIImageView as subview. The contentSize of the ScrollView has been set to the size of the UIImageView.
I implemented zooming and scrolling of the UIImageView.
I need the UIScrollView to keep the scroll rect when I change its frame (proportionally).
How is this done?
My problem is, whenever I change the frame of the UIScrollView the visible rect of the UIImageView changes.
Thanks!
If I understand your problem correctly, you want to shrink the frame of the scroll view without changing what you are able to see inside of the scroll view. You can do this in the following way:
Create a new UIView and set its frame to the position and size that you want to see the content of the scroll view. Turn on the clips to bounds on that view, view.clipsToBounds = yes. Add the scroll view as a subview to the view you created. [view addSubview:scrollview]. Turn clips to bounds off on the scrollview, scrollview.clipsToBounds = no.
Hope that helps.