Dear all,
i have UIView and UIScrollView inside UIViewController.
UIView and UIScrollView has same width, width equal 500,
I need UIView to scroll when I scroll the UIScrollView. How can I achieve this?
P.S: UIView is not a subview of UIScrollView
Thank you for answers!
If i understand correctly u need to add into ur viewControler a horizontalscroll view and then into that view and into that u add ur view and another scrollview.
I hope i understand ur question correctly.
you need to make your UIView as the subview of UIScrollView then only you will be able to scroll the UIView when you scroll your scrollview.
Related
I have UIScrollView with many UIView views added to the content. I would like to convert UIView and its subviews to UIImage and I know how to do it if the UIView is currently visible on the device screen. Is it possible to convert UIView (subview in UIScrollView) into UIImage if UIView is not in UIScrollView visible rect?
Could you just iterate over all subviews taking a screenshot of each UIView inside the UIScrollView ?
The following class may help with taking screenshots:
http://ioscodesnippet.com/2011/08/25/rendering-any-uiviews-into-uiimage-in-one-line/
Hope you find a solution.
Thanks,
Michael
I have a subclass of UIScrollView class and this scroll have vertical content. But I need drag and drop this UIScrollView in the parent view on horizontal direction. How can I implement this?
You must have a specific hierarchy:
Before you do anything you must go to your StoryBored and deselect the Autolayout option under the FileInspector.
View
ScrollView
ContainerView (if you want one or have one)
View
UIControl (if you have one)
THE CONTENTS OF YOUR VIEW.
You must however make a declaration of the scrollView in your header file:
IBOutlet UIScrollView *yourScrollViewName;
In your main under viewDidLoad:
-(void)viewDidLoad {
yourScrollViewName.translatesAutoresizingMaskIntoConstraints = NO;
[yourScrollViewName setScrollEnabled:YES];
[yourScrollViewName setContentSize:CGSizeMake(320 ,554)]; //320 is the x which is the width. change this to make it horizontal.
//554 is the Height this has to be larger that the screen size in order to have vertical scrolling.
[yourScrollViewName setPagingEnabled:NO];
}
Hi everyone. I dragged a UIScrollView to my storyboard, then I added a UIView on top of that UIScrollView. This UIView loads another subview dynamically depending on what the server throws to this app.
The problem is the UIScrollView is not scrolling the content, even though I made the loaded UIView bigger than the UIScrollView. I'm not invoking [myScroller addSubView:myUiView]. Am I doing it right? Thanks in advance!
For every time you change the content try calling
//removeFromSuperview the UIView was set as content view
self.myScroller.contentSize = self.myUiView.frame.size;
[myScroller addSubView:myUiView];
Don't forget to link both views on Interface Builder
PS: In this apporach the subView must not be inside the scrollView on IB
You must set the content size of the scroll view.
Add this in your view controller.
- (void) viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
myScroller.contentSize = CGSizeMake(CGRectGetMaxX(myUiView.frame), CGRectGetMaxY(myUiView.frame));
}
I have a scrollView with its content view and finally a subview on the content view.
I would like to stop scrolling [scrollView scrollEnabled:NO] from the subview. Can I get at the method?
I don't have Xcode in front of me, but can't you get at the superview with self.superview from your subview code?
For instance, like so:
[subview.superview scrollEnabled:NO];
To stop scrolling [scrollView scrollEnabled:NO] from the subview? Maybe you need a viewController which control the views. Do you clear about the MVC?
I need to place a photo in the screen and it should be able to be scrolled or zoomed,
I know UIScrollView does these, so I alloced one, but how about my photo?
I guess I should not just set the photo as the backgroundColor of my UIScrollView, and I haven't found any property of UIScrollView, in the document, to hold an image, such as "imageView", "contentView", or something like that.
So, what should I do to make a picture in my screen and make it able to respond to finger touches?
Thanks a lot!
Add the UIImageView to the UIScrollView and set the min/max scale value to it.
Then implement the following UIScrollViewDelegate function.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return yourImageView;
}
If you want to have multiple items scaled, add all the view into a UIView, and put that UIView inside the UIScrollView. Of course you have to change the return view to that UIView in the above function.
Just add your UIImageView as a subview of the UIScrollView. Also, set the scroll view's contentSize property to be equal to the size of the image view's frame.
THe scrollView is the first step.
Then you should add a UIImageView and load an image inside.
You need also to set the max e min zoomScale properties of the scrollview
And you must implement the scrollview delegate method – viewForZoomingInScrollView: