How to zoom in and zoom out mutiple images on scroll view - iphone

i have a scroll view with multiple images and i am using this code. i have the images with dimensions (2121 x 2892) in Portrait and (2112 x 1500) in landscape mode
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scrollView.pagingEnabled = YES;
scrollView.delegate = self;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.maximumZoomScale = 3.0f;
scrollView.minimumZoomScale = 1.0;
NSInteger numberOfViews = [arrayImages count];
for (int i = 0; i < numberOfViews; i++)
{
CGFloat yOrigin = i * scrollView.frame.size.width;
imageView = [[UIImageView alloc]initWithFrame:CGRectMake(yOrigin +30, 0, self.view.frame.size.width-60 , self.view.frame.size.height)];
imageView.userInteractionEnabled = YES;
imageView.image = [UIImage imageNamed:[arrayImages objectAtIndex:i]];
[scrollView addSubview:imageView];
imageView.userInteractionEnabled = YES;
}
[self.view addSubview:scrollView];
i want to implement the zoomin and zoom out functionality on double tab and moving with two fingers. I saw many sample application but i am not be able to do the same. if anybody have its own code please share with me.

I want to implement the zoomin and zoom out functionality on double tab and moving with two fingers.
For the zoom in on double tap, check out the gesture recogniser part of this tutorial.
As for moving around with 2 fingers, you could use a UIPanGestureRecogniser for 2 touches and change the contentOffset of the scroll view accordingly when a pan is recognised.

simple add a subview to scrollview and add all imageViews in it. and in scrollview's delegate method and do like this
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll {
return view;
}

Related

How to load remote Images and save to a NSMutableArray

I am trying to Load 5 or 6 remotes images to a scrollview and swipe horizontal. I can get the URLs form my webserver (JSON output) , I'm trying to do this using AFnetworking for performances issues .
so far I can get the URL and load one picture to a UIImageview like this (Using Storyboard )
Jsonobject *items = [posterNSMarray objectAtIndex:0]; //load one url only
NSlog (#"Object url %#", items.pUrl); // picture URL
[self.imageview setImageWithURl :[NSURL URLWithString:items.pUrl] placeholderImage :[UIImage imageNamed:#"placeholder"]];
[EDITED QUESTION]
my question is how do I get all the images and save it to a NSMutableArray
Thanks for your help .
[EDIT]
Based upon your comments below, I might actually choose then a different methodology
Bring in All of your images. At this point you can use either UIImageView or UIButton actually to obtain the tap (from the scrollview) you wish. Assign the UIImages to your choice of UIButton or UIImageView, and the place them on your scrollview as you wish. You will have to dynamically create the actions for each Button or ImageView. Your action creation should then bring up another View to be place atop you scrollview, or another viewcontroller that you animate to, etc... In a View Controller you will have your UIImageView as full screen. At this point you can implement your own UIGestureRecognizers to implement the double taps, etc...
I would use a UIListView. Here is a great link to custom UIListView implementation.
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
I would load your images into an NSMutableArray, to be used by the drawing routine of the custom UITableView.
As for swiping, you can capture the swipe events, then you can do with the list items as you please (i.e. delete, edit, etc... from your image array).
Another link:
http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/
From your question and comments it seems like you want to load a UIScrollView with multiple images and then swipe through each one. It also sounds like you want to be able to tap one and have it launch a blown up image for the user to view.
I wrote some of these functions for an old project (they are a little rough) but you may be able to use them as they are how I accomplished what I think you were asking.
-(void)setupPictures
{
imageSectionSlider = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, IMAGE_HEIGHT)];
imageSectionSlider.showsVerticalScrollIndicator = NO;
imageSectionSlider.showsHorizontalScrollIndicator = NO;
imageSectionSlider.pagingEnabled = YES;
imageSectionSlider.bounces = NO;
UIView* tilesHolder = [[UIView alloc]initWithFrame:CGRectMake(0, 0, (([[thisStory imageList]count] * (self.frame.size.width))), IMAGE_HEIGHT)];
tilesHolder.userInteractionEnabled = YES;
for (int count = 0; count < [[thisStory imageList]count]; count++)
{
[tilesHolder addSubview:[self createImageTile:[[thisStory imageList]objectAtIndex:count] Count:count Rect:CGRectMake( 320*count , 0, 320, IMAGE_HEIGHT)]];
}
[imageSectionSlider setContentSize:CGSizeMake( tilesHolder.frame.size.width , tilesHolder.frame.size.height)];
[imageSectionSlider addSubview:tilesHolder];
[tilesHolder release];
}
-(UIView*)createImageTile:(ImageItem*)input Count:(int)count Rect:(CGRect)rect
{
UIView* imageTile = [[UIView alloc]initWithFrame:rect];
[imageTile setTag:count];
UIImageView* image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, imageTile.frame.size.width, imageTile.frame.size.height - 45)];
[image setImage:[input imageData]];
image.contentMode = UIViewContentModeScaleAspectFill;
image.clipsToBounds = YES;
image.userInteractionEnabled = YES;
image.tag = count;
UIGestureRecognizer* featureImageGesRec = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(countTaps:)];
[image addGestureRecognizer:featureImageGesRec];
[featureImageGesRec release];
[imageTile addSubview:image];
[image release];
return [imageTile autorelease];
}
- (void)countTaps:(NSObject*)sender {
tapCount++;
if (tapCount == 1) {
//do something with single tap
}
else if (tapCount == 2)
{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self doubleTap:sender];
}
}
-(void)doubleTap:(NSObject*)sender
{
UITapGestureRecognizer* item = (UITapGestureRecognizer*)sender;
tapCount = 0;
//FullSizeImage
ImageItem* selectedItem = [[thisStory imageList]objectAtIndex:item.view.tag];
ExpandedView* pictureView = [[ExpandedView alloc]initWithImage:[selectedItem imageData]];
[thisParent.navigationController pushViewController:pictureView animated:YES];
[pictureView release];
}
Just pass your async loaded image here in this line...
[tilesHolder addSubview:[self createImageTile:/*Image*/ Count:count Rect:CGRectMake( 320*count , 0, 320, IMAGE_HEIGHT)]];
if you use AFNetworking Conect, you use Image Request concept :-
try this code:-
- (void)setupPage
{
scrollPage = 0 ;
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0f,0, 320,367)];
[scrollView setBackgroundColor:[UIColor clearColor]];
[scrollView setDelegate:self];
[self.view addSubview:scrollView];
NSUInteger nimages = 0;
CGFloat cx = 0;
CGFloat cy = 0;
for (; nimages < [stealArr count]; nimages++)
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,320.0f,367)];
CGRect rect = imageView.frame;
rect.size.height = 331;
rect.size.width = 320.0f;
rect.origin.y = 0.0f;
rect.origin.x = 0.0f+cx;
imageView.frame = rect;
[imageView setBackgroundColor:[UIColor clearColor]];
imageView.contentMode = UIViewContentModeScaleToFill;
[scrollView addSubview:imageView];
[imageView setImageWithURL:[NSURL URLWithString:#"http://i.imgur.com/r4uwx.jpg"] placeholderImage:[UIImage imageNamed:#"placeholderImage"]];
cx += scrollView.frame.size.width;
cy += scrollView.frame.size.height;
}
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 331.0f, 320, 36)] ;
[pageControl setCurrentPage:0] ;
[pageControl addTarget: self action: #selector(pageControlClicked:) forControlEvents: UIControlEventValueChanged] ;
[pageControl setDefersCurrentPageDisplay: YES];
[pageControl setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:pageControl];
pageControl.numberOfPages = [stealArr count];
[scrollView setContentSize:CGSizeMake(cx,[scrollView bounds].size.height)];
[scrollView setPagingEnabled:TRUE];
}
when Your are scroll the page
- (void)scrollViewDidScroll:(UIScrollView *)sender {
// We don't want a "feedback loop" between the UIPageControl and the scroll delegate in
// which a scroll event generated from the user hitting the page control triggers updates from
// the delegate method. We use a boolean to disable the delegate logic when the page control is used.
// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat pageWidth = scrollView.frame.size.width;
scrollPage = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = scrollPage;
be to unload the views+controllers which are no longer visible
}
for Paging
- (void)pageControlClicked:(id)sender
{
UIPageControl *thePageControl = (UIPageControl *)sender ;
// we need to scroll to the new index
[scrollView setContentOffset: CGPointMake(scrollView.bounds.size.width * thePageControl.currentPage, scrollView.contentOffset.y) animated: YES] ;
}

iOS - UIScrollView is not working (it doesn't scroll at all - the image stays fixed)

I would like to display an image (width: 320 pixels, height: 1250 pixels) in an image view.
When I compile the application I get no scrolling at all. The view stays fixed.
What I did:
Added an UIScrollView via Interface Builder to my view.
Added an UIImageView via Interface Builder to my view.
Verified that UIImageView is below UIScrollView in Interface Builder.
Set the size of the UIScrollView with ViewDidLoad.
How do I do this?
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
scrollView.contentSize = CGSizeMake(320, 1250);
}
Screenshots:
ImageView:
ScrollView:
I just have done the same task..
Try this one.....
scrollView.delegate = self;
scrollView.scrollEnabled = YES;
int scrollWidth = 120;
scrollView.contentSize = CGSizeMake(scrollWidth,80);
int xOffset = 0;
imageView.image = [UIImage imageNamed:[imagesName objectAtIndex:0]];
for(int index=0; index < [imagesName count]; index++)
{
UIImageView *img = [[UIImageView alloc] init];
img.bounds = CGRectMake(10, 10, 50, 50);
img.frame = CGRectMake(5+xOffset, 0, 50, 50);
NSLog(#"image: %#",[imagesName objectAtIndex:index]);
img.image = [UIImage imageNamed:[imagesName objectAtIndex:index]];
[images insertObject:img atIndex:index];
scrollView.contentSize = CGSizeMake(scrollWidth+xOffset,110);
[scrollView addSubview:[images objectAtIndex:index]];
xOffset += 70;
}
Also set this one....
imagesName = [[NSArray alloc]initWithObjects:#"image1.jpg",#"image2.jpg",#"image3.jpg",#"image4.jpg",#"image5.jpg",#"image6.png",#"image7.png",#"image9.png",nil];
images = [[NSMutableArray alloc]init];
So for me the problem was that setting the content size didn't work in viewDidLoad(). I tried everything and I didn't understand why it wouldn't want to work, and then I tried the same stuff in viewDidAppear() and it magically worked...
From you last screenshot and from your comments it looks like your scrollView is way to big.
The scrollview must be visible on screen completely. For example a full screen UIScrollView on iPhone would have a size of 320 x 460.
If the scrollview is the same size as its content you can't scroll.
The greenish rectangle shows the size of your scrollview, the pinkish the size of your content (your image):
Xcode 11+, Swift 5
You can find the complete solution here.
I came across this same issue on iOS6 and the solution was to programmatically adjust the ContentSize.
So I will just quote from Raja (above) to show this:
CGSize scrollViewContentSize = CGSizeMake(320, 400);
[self.scrollView setContentSize:scrollViewContentSize];
NOTE: I was not having this issue on iOS5.. seems like iOS6 decided to do alot of prank just like the rotation/orientation saga
Since Xcode 5 it does not work like before. Also scrolling to the end of a scrollable text field makes problems. There are also differences between doing it on iPhone or iPad. On iPhone it worked without delayed timer.
This worked for me:
- (void)viewDidLoad
{
[super viewDidLoad];
NSTimer *timerforScrollView;
timerforScrollView =[NSTimer scheduledTimerWithTimeInterval:0.1
target:self selector:#selector(forScrollView)userInfo:nil repeats:NO];
}
- (void) forScrollView {
[scrollviewPad setScrollEnabled:YES];
[scrollviewPad setContentSize:CGSizeMake(768, 1015)]; // must be greater then the size in Storyboard
}
I found I had a similar problem but none of the above code worked. The issue was due to autolayout. I found that if I turned off autolayout by going to the storyboard clicking on Utilities -> File Inspector and unchecked Use Autolayout the scrolling did work (I also set scroll.contentSize = ...).
Sometimes autoLayout checkbox is ticked in the xib. That also creates this issue in xcode 5. Which makes the UIScrollView scrolling off.
Don't forget to add the category protocol to the interface, like this
#interface MyViewController : <UIScrollViewDelegate>
If you don't, you will not be able to set the scroll view delegate to self
(i.e. [MyScrollView setDelegate:self];)
If you do this, it should work.
My code is:
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[contentScrollView setDelegate:self];
[contentScrollView setScrollEnabled:YES];
contentScrollView.contentSize = CGSizeMake(310, 500);
contentScrollView.frame = CGRectMake(5, 188, 310, 193);
}
Did you assign the scroll's view delegate? Always remember these:
[self.scrollView setDelegate:self];
[self.scrollView setScrollEnabled:YES];
The image view has to be a subview (so inside AND below) of the scrollview. From your description it seems they are paralell
You forgot one line. Add this to your view load function:
[scrollView setScrollEnabled:YES];
You could try disabling AutoLayout. In XCode 5 I tested all the above answers and I could only scroll it by disabling autolayout and activating all autosizing masks under the Size Inspector. The following code was used too:
self.scrollView.contentSize = CGSizeMake(320, 900);
self.scrollView.delegate = self;
self.scrollView.scrollEnabled = YES;
self.scrollView.frame = self.view.frame;
CGRect scrollViewFrame = CGRectMake(0, 0, 320, 400);
self.scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
[self.view addSubview:self.scrollView];
CGSize scrollViewContentSize = CGSizeMake(320, 400);
[self.scrollView setContentSize:scrollViewContentSize];
scrollView.delegate = self;
[self.scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
NSUInteger nimages = 0;
CGFloat cx = 0;
for (; ; nimages++) {
NSString *imageName = [NSString stringWithFormat:#"image%d.jpg", (nimages + 1)];
UIImage *image = [UIImage imageNamed:imageName];
if (image == nil) {
break;
}
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.size.height = image.size.height;
rect.size.width = image.size.width;
rect.origin.x = ((scrollView.frame.size.width - image.size.width) / 2) + cx;
rect.origin.y = ((scrollView.frame.size.height - image.size.height) / 2);
imageView.frame = rect;
[scrollView addSubview:imageView];
[imageView release];
cx += scrollView.frame.size.width;
}
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
Assuming that scrollView is a subview of view and fills it entirely you can use the following in viewDidLoad:
[scrollView setContentSize: CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)];
I had a UIScrollView that was not scrolling and this allowed it to scroll.
Just add code
scrollView.contentSize = CGSizeMake(WIDTH,HEIGHT);
to method -(void)viewDidLayoutSubviews.
For more information checkout Stanford CS193p Lecture No 8 to understand View Controller Life cycle.
I had the same issue and was looking for the answer in this thread. I tried all the stuff, but nothing works. Then I found this:
.
You just need to deselect "Use Auto Layout" in File Inspector of your ViewController. Ta-Da, it works immediately for me. Enjoy.

apply zoom event with array of images of image view in UIScrllView

- (void)viewDidLoad
{
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapDetected:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
int numberOfImages = 32;
CGFloat currentX = 0.0f;
for (int i=1; i <= numberOfImages; i++) {
// create image
NSString *imageName = [NSString stringWithFormat:#"page-%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
imageView = [[UIImageView alloc] initWithImage:image];
// put image on correct position
CGRect rect = imageView.frame;
rect.origin.x = currentX;
imageView.frame = rect;
// update currentX
currentX +=454; //mageView.frame.size.width;
[scrollView addSubview:imageView];
[imageView release];
}
[scrollView addGestureRecognizer:tapGesture];
scrollView.contentSize = CGSizeMake(currentX, 800);
scrollView.pagingEnabled=YES;
scrollView.userInteractionEnabled = YES;
scrollView.maximumZoomScale = 15;
scrollView.minimumZoomScale = 0.5;
scrollView.bounces = NO;
scrollView.bouncesZoom = NO;
scrollView.delegate = self;
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:scrollView];
[scrollView release];
[super viewDidLoad];
}
}
in above code when i apply zoom or tap event with a single image then it work for that. But when same event apply for array of image then not working. why is it happened?
Its quiet complex to implement zoom in this kind of image flow. Anyway i wil suggest you one idea,
Add the gesture to each imageView. In the method, add a new scrollview, with the respective imageView.. then implement zoom.
EDIT:
In the tapgesture method,
1.Find out the which imageView is visible at that time.
2.Then create a new scrollview,with that single imageview.
3.Implement zoom functionality in that new scrollview.
4.During zoom out,If the new scrollview size is equal to the actual value,remove the new scrollview fro the super view so that the array of images is visible.
Simplest way is create a big wrapper view first, and insert it into ScrollView.
And then add all your imageViews to the wrapper view.

Horizontal UIScrollView and hundreds of thumbnail images in iOS?

I need to create a horizontal UIScrollView which to hold hundreds of thumbnail images, just like a slide of thumbnails.
For example, there will be 10 thumbnails showing in a single screen, each of them are horizontally adjacent to each other.
My problem is that I don't know how to make a horizontal UIScrollView to hold the multiple thumbnails which showing at the same time ?
A sample photo is as below. See the bottom part of the screen.
Thanks.
You can add all the thumbnails programatically to your scrollview and use the setContentSize method of UIScrollView. you have to pass 2 values in contentOffset. 1 for width and 1 for height. Please follow link to explore more on this. If you need further help please leave a comment.
Hope it helps.
Please consider Following example.
- (void)setupHorizontalScrollView
{
scrollView.delegate = self;
[self.scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = NO;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
NSUInteger nimages = 0;
NSInteger tot=0;
CGFloat cx = 0;
for (; ; nimages++) {
NSString *imageName = [NSString stringWithFormat:#"image%d.jpg", (nimages + 1)];
UIImage *image = [UIImage imageNamed:imageName];
if (tot==15) {
break;
}
if (4==nimages) {
nimages=0;
}
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.size.height = 40;
rect.size.width = 40;
rect.origin.x = cx;
rect.origin.y = 0;
imageView.frame = rect;
[scrollView addSubview:imageView];
[imageView release];
cx += imageView.frame.size.width+5;
tot++;
}
self.pageControl.numberOfPages = nimages;
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
}
I suggest you to look at nimbus
Check out bjhomer's HSImageSidebarView project. It lets you load a scrollview horizontally or vertically and load in the images. Super easy to implement.
First of all, at storyboard drag and drop the scroll view and make the outlet of scrollview named scrollView. Two array one is mutable and one is immutable.
#property(nonatomic,strong)IBOutlet UIScrollView *scrollView;
#property(nonatomic,strong)NSMutableArray *images;
#property(nonatomic,strong)NSArray *imagesName;
The immutable array only store the images which we want to show on the scroll view.Make sure UIscrollview delegate is defined.
In viewcontoller.m file in didload function do following code:
imagesName = [[NSArray alloc]initWithObjects:#"centipede.jpg",#"ladybug.jpg",#"potatoBug.jpg",#"wolfSpider.jpg", #"ladybug.jpg",#"potatoBug.jpg",#"centipede.jpg",#"wolfSpider.jpg",nil];
// mutable array used to show the images on scrollview dynamic becaus after one
// image when scroll other will come
images = [[NSMutableArray alloc]init];
scrollView.delegate = self;
scrollView.scrollEnabled = YES;
int scrollWidth = 120;
scrollView.contentSize = CGSizeMake(scrollWidth,80);
int xOffset = 0;
//the loop go till all images will load
for(int index=0; index < [imagesName count]; index++)
{
UIImageView *img = [[UIImageView alloc] init];
// make the imageview object because in scrollview we need image
img.frame = CGRectMake(5+xOffset, 0, 160, 110);
// the offset represent the values, used so that topleft for each image will
// change with(5+xOffset, 0)and the bottomright(160, 110)
NSLog(#"image: %#",[imagesName objectAtIndex:index]);
img.image = [UIImage imageNamed:[imagesName objectAtIndex:index]];
// The image will put on the img object
[images insertObject:img atIndex:index];
// Put the img object at the images array which is mutable array
scrollView.contentSize = CGSizeMake(scrollWidth+xOffset,110);
//scroll view size show after 125 width the scroll view enabled
[scrollView addSubview:[images objectAtIndex:index]];
// set images on scroll view
xOffset += 170;
}
You can calculate content size width of the scrollview as width = number of images * size of each image. Then set contentSize of the scrollview to this width and the height that you want (scrollView.contentSize = CGSizeMake(width, height))

How to implement two separate UIScrollViews with nested UIImageViews...only one is zooming

Ok, I have been working on solving this problem all day, and I am getting really close. I am trying to have create a way to view more than one scrollView/imageView nested pair that allows for zooming on an image.
When the view loads, there is just one scrollView that takes up the whole screen, but then when a button is pressed, I cut the width of the first scrollView in half, and unhide another (which has a nested imageView in it as well) right next to it. So there is a split view effect, and ideally the user will be able to pinch and zoom each image separately.
So I have all that working except for the separate pinch and zoom part. No matter where I pinch on the screen, only the first scrollView zooms. So even though I am touching another scrollView, it is still only affecting the first.
I have them setup in IB, and then they are setup in viewDidLoad this way:
[scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.minimumZoomScale = 1;
scrollView.maximumZoomScale = 5;
scrollView.delegate = self;
[scrollView setScrollEnabled:YES];
imageView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"monitor.JPG"]];
[scrollView addSubview:imageView3];
//[scrollView setFrame:CGRectMake(0, 0, 1024, 660)];
[scrollView1 setBackgroundColor:[UIColor blackColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView1.minimumZoomScale = 1;
scrollView1.maximumZoomScale = 5;
scrollView1.delegate = self;
[scrollView1 setScrollEnabled:YES];
imageView31 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"monitor.JPG"]];
[scrollView1 addSubview:imageView31];
And then I hide and unhide different scrollViews (I have 40 depending on the segmentedControl index on the toolbar. Am I headed in the right direction? Is it possible to have two separately accessible scrollViews?
Any help would be appreciated.
Thanks!
EDIT:
Ok so I went through and updated the clipToBunds bit...DUH. It definitely makes it look better, but still isn't solving the problem. Here is the code I am calling depending on the selected index:
-(void) pickedOne{
if(segment.selectedSegmentIndex == 0){
[scrollView setFrame:CGRectMake(0, 0, 1024, 660)];
[scrollView setContentSize:CGSizeMake(1024, 660)];
scrollView.hidden = NO;
scrollView1.hidden = YES;
scrollView2.hidden = YES;
scrollView3.hidden = YES;
}else if(segment.selectedSegmentIndex == 1){
[scrollView setFrame:CGRectMake(0, 0, 512, 660)];
scrollView.zoomScale = 1.0;
scrollView.hidden = NO;
[scrollView1 setFrame:CGRectMake(512, 0, 512, 660)];
scrollView1.zoomScale = 1.0;
scrollView1.hidden = NO;
scrollView2.hidden = YES;
scrollView3.hidden = YES;
}
Is there anything majorly wrong with that approach?
If I pinch to zoom on the right scrollView, it makes the scroll view bigger, (but doesn't increase the size of the scrollView2 image) but it DOES increase the size of the first scrollView's image when you pinch inside of EITHER scrollViews...strange
scrollView.clipsToBounds = NO; // default is NO, we want to restrict drawing within our scrollview
Isn't this the opposite of what you want? Setting it to YES restricts restricts drawing to within your scrollview.
It sounds to me like you aren't resizing the scrollview. Are you resizing its contents or the image view within it? Can you post the code that is called when you tap the button?