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:
Related
I have a textView which is not editable so my textView is only readable. And there is a ImageView on the top of textView. I want that, when the textView is scrolling, ImageView (Y position) disappear slowly depends on How many the textView scrolled.. If I should give an example, it looks like Twitter "Me" page but non blurred. I hope I was clear.
First of call UIScrollViewDelegate, make your viewcontroller delegate to self.Because it's subclass of UIScrollview.
and implement scrollView function according to your need.Suppose you want to disappear image after scrolling finished. then implement this method.
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(#"Finished scrolling");
}
I have an UIScrollView with many buttons and some labels. My question is: How can I easily zoom UIScrollView content (with two fingers)?
Thank you very much.
UIScrollViews already support zoom using pinch gesture, you just need to implement the delegate method
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView {
// Return the view that you want to zoom
return self.viewZoom;
}
Returning the view you want to zoom.
As Andrea pointed out the UIScrollView already supports zoom feature.
Follow these steps:
Add a UIView (say viewZoom) to the scrollView by giving same width and height as that of scroll view.
Add all UI components (Buttons etc) to viewZoom.
Set maximumZoomScale property of scroll view to '2' (or any other value as per your requirement).
Set your view controller as delegate to ScrollView(scrollView.delegate = self).
Implement - (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollViewin view controller and return the "viewZoom" you added to the scroll view from this method.
Is it possible to add a static background to a collectionview because at the moment the background scrolls with the cells and the image looks quite bad.
my code at the moment
collectionView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bg.png"]];
There are 2 ways to do what you're asking.
add the background to the UICollectionView as a subview like you're doing now and implement the scrollViewDidScroll: delegate method. Inside that method, set the frame of the background view based on the contentOffset of the collection view which will make it appear to be static on the screen. You will just need to set the frame's Y origin to be the contentOffset.y and it should work. (If there is a non-zero contentInset you may need to do a bit of additional math to get it right.)
add the background to the superview of your collection view, underneath the collection view. This is an easier and probably more efficient solution since you don't need to mess with the contentOffset at all since the background will not be in the scroll view itself.
if I understand your requirement correctly, here's how you can do it:
1) Add your static image as a subview to the parentView.
2) Set the backgroundColor of collectionView to [UIColor clearColor]
3) Add collection view as a subview to the parentView.
I have a scroll view with an image view. And I want to zoom the image in all direction equally. But when I am trying to do it's not happening.
But its zooming image only in vertical direction not in horizontal direction. I have done this:
[monthView setImage:[monthArray objectForKey:dateString] ];
scrollView1.contentSize=CGSizeMake(1280, 960);
#pragma scrollview delegates
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return monthView;
}
Write minimumZoomScale and maximumZoomScale value of scrollView in viewDidLoad
_scrollview.minimumZoomScale=1.0;
_scrollview.maximumZoomScale=2.0;
Set zooming scale for scrollview. Like:
self.myScrollView.minimumZoomScale = 1.0;
self.myScrollView.maximumZoomScale = 5.0f;
And Make sure monthView is a subview of scroll view.
Hope this helps. :)
1 Set your view controller up as a .
2 Draw your UIScrollView the size you want for the rectangle at the center of the view. Set the max zoom in the inspector to something bigger than 1. Like 4 or 10.
3 Right click on the scroll view and connect the delegate to your view controller.
4 Draw your UIImageView in the UIScrollView and set it up with whatever image you want. Make it the same size as the UIScrollView.
5 Ctrl + drag form you UIImageView to the .h of your View controller to create an IBOutlet for the UIImageView, call it something clever like imageView.
6 add this code.
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView {return self.imageView;}
7 Run project.
I have Create UIScrollview Programatically.I have added 5 View and each view have Imageview with image. I am doing zoom in/zoom out image using UIPanGesture i can zoom in and zoom out image using PanGesture but when i scroll the scrollview then UIImageview not set its actual frame. i want to resize subview of scrollview when scrollview scroll.
Thanks in Advance
Set your view controller a delegate of your scrollview:
scrollview.delegate = self;
Then, implement this delegate method in your viewcontroller:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
// resize subview of scrollview here
}
You need to set some object as the scrollview's delegate and then implement this method:
-(void)scrollViewDidScroll:(UIScrollView *)inScrollView
Then you can do whatever you would like with the subviews whenever the scrollview scrolls (this includes automated scrolling, not just when the user scrolls).