Getting Image index - iphone

I am developing an app in that i have 15 images for stored in an array as front images and another 15 images as back image. I want to add that image to scrollview vertically i have done that successfully but now my problem is that how can I compare that two array images.
Adding front images on vertical scrollview added succesfully but not randomly shuffled, ie when I double tap on the front image the back array image is displayed but still front image present in that imageview.
Please help me out to solve this problem.
Thanks in advance.
Please check my code :
- (void)viewDidLoad
{
[super viewDidLoad];
AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
delegate.front=TRUE;
delegate.back=FALSE;
UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[scrollView setPagingEnabled:YES];
[scrollView setShowsHorizontalScrollIndicator:NO];
FrontsCards=[[NSMutableArray alloc]initWithObjects:#"cloub1.png",#"cloub2.png",#"cloub3.png",#"cloub4.png",#"cloub5.png",#"cloub6.png",#"cloub7.png",#"cloub8.png",#"cloub9.png",#"cloub10.png",#"cloub11.png",#"cloub12.png",#"diamond1.png",#"diamond2.png",#"diamond3.png",#"diamond4.png",#"diamond5.png", nil];
for(int m=0; m<[FrontsCards count];m++)
{
ImgView.tag=m;
int randIdx=arc4random()%[FrontsCards count];
NSString *imageName=[FrontsCards objectAtIndex:randIdx];
// NSLog(#"%d",randIdx);
NSString *fullImageName=[NSString stringWithFormat:#"%#",imageName];
int padding=25;
// padding is given.
CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);
ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];
[ImgView setImage:[UIImage imageNamed:fullImageName]];
[ImgView setContentMode:UIViewContentModeScaleAspectFill];
[scrollView addSubview:ImgView];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(doubleTapImgView:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.delegate = self;
[self.ImgView addGestureRecognizer:doubleTap];
self.ImgView.userInteractionEnabled=YES;
}
CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*[FrontsCards count], scrollView.frame.size.height);
[scrollView setContentSize:scrollViewSize];
[self.view addSubview:scrollView];
}
- (void)doubleTapImgView:(UITapGestureRecognizer *)gesture
{
AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
delegate.back=TRUE;
delegate.front=FALSE;
NSLog(#"%d", gesture.view.tag);
NSLog(#"double-tap");
BackCards =[[NSMutableArray alloc]initWithObjects:#"card1.jpg",#"card2.jpg",#"card3.jpg",#"card4.jpg", nil];
UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[scrollView setPagingEnabled:YES];
[scrollView setShowsHorizontalScrollIndicator:NO];
for(int m=0; m< [BackCards count];m++)
{
NSString *imageName=[BackCards objectAtIndex:m];
NSString *fullImageName=[NSString stringWithFormat:#"%#",imageName];
int padding=25;
// padding is given.
CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);
ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];
[ImgView setImage:[UIImage imageNamed:fullImageName]];
[ImgView setContentMode:UIViewContentModeScaleAspectFill];
[scrollView addSubview:ImgView];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(doubleTapImgView:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.delegate = self;
[self.ImgView addGestureRecognizer:doubleTap];
self.ImgView.userInteractionEnabled=YES;
}
CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*[FrontsCards count], scrollView.frame.size.height);
[scrollView setContentSize:scrollViewSize];
[self.view addSubview:scrollView];
}

For achieving this one you can set Tag value for every image when you tap on that particuler image you'l get tag value and use that tag value.
self.imagview.tag=Unique_tagValue;
when click on that image you can set image from another Array.
self.imageview.image=[UIImage imageNamed:[backArray objectAtIndex:self.imageview.tag]];
EDIT:-
in viewDidLoad method set tags for imageview like this, ImgView.tag=m+100;
keep below code in doubleTapImgView method
for(int m=0; m< [BackCards count];m++)
{
UIImageView *imgview=(UIImageView *)[scrollview viewWithTag:m+100];
imgview.image=[UIImage imagNamed:[BackCards objectAtIndex:m]];
}
Subview Translation:-
[self.view bringSubviewToFront:frontview];

Either you can use the same name for the images in backArray and front Array or you can set the tag value of each image uniquely and compares that tags to solve the problem.
imgV.tag=tagValue;
Hope this helps.

Related

How to add images to UIPageViewController?

I have a UIPageViewController with 5 screens. Please see the below image
I need to add some images instead of the label Screen #1, Screen #2, etc.
Here is my code
Can anyone please tell me the solution?
Try this code..
Add whatever yor images in your imageArray array;
NSArray *imageArray=[[NSArray alloc]initWithObjects:#"SpaceTheme.png",#"BeachTheme.png",#"vintage.png", nil];
ScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320,480)];
[Scroll setPagingEnabled:YES];
[Scroll setShowsHorizontalScrollIndicator:NO];
for(n=0; n< [imageArray count];n++)
{
NSString *imageName=[imageArray objectAtIndex:n];
NSString *fullImageName=[NSString stringWithFormat:#"%#",imageName];
CGRect imageViewFrame;
int padding=20;
imageViewFrame=CGRectMake(Scroll.frame.size.width*n+padding-10,Scroll.frame.origin.y-130,Scroll.frame.size.width-1*padding, Scroll.frame.size.height);
UIImageView *imageView=[[UIImageView alloc]initWithFrame:imageViewFrame];
[imageView setImage:[UIImage imageNamed:fullImageName]];
[imageView setContentMode:UIViewContentModeScaleAspectFit];
[Scroll addSubview:imageView];
pagecontrol.numberOfPages = 3; // Give numbre of pages here
pagecontrol.currentPage = 0;
[self.view addSubview:pagecontrol];
}
Scroll.delegate=(id)self;
CGSize scrollViewSize=CGSizeMake(Scroll.frame.size.width*[imageArray count], Scroll.frame.size.height);
[Scroll setContentSize:scrollViewSize];
[self.view addSubview:Scroll];

Getting index in NSMutableArray of selected or tapped image

I am developing an app where I add images to an NSMutableArray and display them in an image view.
My problem is that I will don't know how to get the index of the selected or tapped image in my app.
FrontsCards=[[NSMutableArray alloc]initWithObjects:#"cloub1.png",#"cloub2.png",#"cloub3.png",#"cloub4.png", nil];
for(int m=0; m< [FrontsCards count];m++)
{
NSString *imageName=[FrontsCards objectAtIndex:m];
NSString *fullImageName=[NSString stringWithFormat:#"%#",imageName];
int padding=25;
CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);
ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];
[ImgView setImage:[UIImage imageNamed:fullImageName]];
[ImgView setContentMode:UIViewContentModeScaleAspectFill];
[scrollView addSubview:ImgView];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(doubleTapImgView:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.delegate = self;
[self.ImgView addGestureRecognizer:doubleTap];
self.ImgView.userInteractionEnabled=YES;
}
CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*[FrontsCards count], scrollView.frame.size.height);
[scrollView setContentSize:scrollViewSize];
[self.view addSubview:scrollView];
What should I do in my tap gesture recognizer to get the index of the image?
- (void)doubleTapImgView:(UITapGestureRecognizer *)gesture
{
NSLog(#"double-tap");
}
set a tag to each imageView you using like this :
ImgView=[[UIImageView alloc]initWithFrame:imageViewFrame];
ImgView.tag = m;
and then replace this method:
- (void)doubleTapImgView:(UITapGestureRecognizer *)gesture
{
NSLog(#"double-tap");
NSLog(#"%d", gesture.view.tag);
}
it will print you the index of the image in the imageView
maybe you can use something like this:
first add the name of the image as the accessibilityIdentifier of the the imageview
[imgView setAccessibilityIdentifier:imageName];
then in the tapRecognizer:
-(void)doubleTapImgView:(UITapGestureRecognizer *)gesture{
UIImageView *imgView = (UIImageView *)gesture.view;
int idx = [FrontCards indexOfObject:[imgView accessibilityIdentifier]];
}

Scrolling top to bottom using UIScrollView

I am looking for an example that show just vertical scrolling in iPhone.
The Apple supplied Scrolling example allows swiping of images left to
right.
Example Link
Example Link
I want to have my images scroll top to bottom like Instagram
App.
I research about it and found lots of example, but they all show
horizontal scrolling.
Example
Example
Example
Does anyone know how to do this?
I appreciate if you send me a link to a tutorial.
Hi i solved your problem with apple code,
just change the function with
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(0,curXLoc);
view.frame = frame;
curXLoc += (kScrollObjHeight);
}
}
// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake(([scrollView1 bounds].size.width),kNumImages * kScrollObjHeight)];
}
or if you want sample then i will give you
For your purpose refer your link:
http://idevzilla.com/2010/09/16/uiscrollview-a-really-simple-tutorial/
There is a code like:
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
For horizontal scrolling you need to set the width of contentSize property to a higher value than the scroll view's frame width. Likewise for vertical scrolling you need to set the height of contentSize property to a higher value than the scroll view's frame height.
Reference
In the above code it can be done like:
scroll.contentSize = CGSizeMake(self.view.frame.size.width, numberOfViews * self.view.frame.size.height);
You can use the following code to scroll images from top to bottom and vice versa.!!
- (void)viewDidLoad
{
//....
UISwipeGestureRecognizer *recognizer;
//for scrolling up
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(SwipeUp)]; // calling method SwipeUp
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[[self view] addGestureRecognizer:recognizer];
//for scrolling down
UISwipeGestureRecognizer *recognizer1;
recognizer1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(SwipeDown)]; //calling method SwipeDown
[recognizer1 setDirection:(UISwipeGestureRecognizerDirectionDown)];
[[self view] addGestureRecognizer:recognizer1];
}
//Initialise and synthesise IBOutlet UIImageView *bgImage;
-(IBAction)SwipeUp
{
[bgImage setImage:[UIImage imageNamed:#"yourImage1"] ];
bgImage.opaque=YES;
[self.view addSubview:bgImage];
}
-(IBAction)SwipeDown
{
[bgImage setImage:[UIImage imageNamed:#"yourImage2"] ];
bgImage.opaque=YES;
[self.view addSubview:bgImage];
}
I don't know if I understood correctly what you want to accomplish but basically you can set the position of you scrollView using setContentOffset.
CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - self.scrollView.bounds.size.height);
[scrollView setContentOffset:bottomOffset animated:YES];
There are several ways of doing this for example:
Using the UITableView with Custom cell
Adding UIScrollingView & adding the content/images & increasing the
height of scrollview according to number of objects in array.
Here is the code snippet which creates a 2*2 Grid for images :
//Over here adding the image names into the Array
NSMutableArray *imageArray=[[NSMutableArray alloc]init];
[Arr addObject:[UIImage imageNamed:#"image_1.png"]];
[Arr addObject:[UIImage imageNamed:#"image_2.png"]];
[Arr addObject:[UIImage imageNamed:#"image_3.png"]];
[Arr addObject:[UIImage imageNamed:#"image_4.png"]];
[Arr addObject:[UIImage imageNamed:#"image_5.png"]];
// Initlaizing the ScrollView & setting the frame :
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,320, 460)];
[scrollView setBackgroundColor:[UIColor clearColor]];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
int row = 0;
int column = 0;
for(int i = 0; i < imageArray.count; i++) {
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor=[UIColor clearColor];
button.frame = CGRectMake(column*160+0,row*210+10, 160, 190);
[button setImage:[imageArray objectAtIndex:i] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor clearColor]];
[button addTarget:self action:#selector(chooseCustomImageTapped:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[view1 addSubview:button];
if (column == 1) {
column = 0;
row++;
} else {
column++;
}
}
[scrollView setContentSize:CGSizeMake(320, (row+1) * 210)];
[self.view addSubview:view1];
//Here is the method used for Tapping :
- (IBAction)chooseCustomImageTapped:(id)sender
{
}
Now,once the scrollView is ready for Vertical scrolling, you can do your own customization accordingly. I hope this would work for you.

How add a UIButton on every image of image view which is in scroll view?

i have an iPhone app in which i have several images. These images add in image view. That image view add sub view with scroll view. Now i want to add a transparent button on every image. How can i do that? I have shown my code below:
- (void)layoutScrollImages{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollWidth);
}
}
// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake((kNoImages * 500), 700)];
}
- (void)viewDidLoad{
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
// 1. setup the scrollview for multiple images and add it to the view controller
//
// note: the following can be done in Interface Builder, but we show this in code for clarity
[scrollView1 setBackgroundColor:[UIColor blackColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView1.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView1.scrollEnabled = YES;
//imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"image0.jpg"]];
[scrollView1 addSubview:imageView];
[scrollView1 setContentSize:CGSizeMake(500,700)];
scrollView1.minimumZoomScale = 1;
scrollView1.maximumZoomScale = 3;
scrollView1.delegate = self;
[scrollView1 setScrollEnabled:YES];
// pagingEnabled property default is NO, if set the scroller will stop or snap at each photo
// if you want free-flowing scroll, don't set this property.
scrollView1.pagingEnabled = YES;
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= kNoImages; i++)
{
NSString *imageName = [NSString stringWithFormat:#"page-%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *ImageView = [[UIImageView alloc] initWithImage:image];
// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
CGRect rect = ImageView.frame;
rect.size.height = kScrollHeight;
rect.size.width = kScrollWidth;
ImageView.frame = rect;
ImageView.tag = i; // tag our images for later use when we place them in serial fashion
UIButton *btnView2= [UIButton buttonWithType:UIButtonTypeCustom];
[btnView2 setTitle:#"view" forState:UIControlStateNormal];
[btnView2 addTarget:self action:#selector(View:)forControlEvents:UIControlEventTouchDown];
[btnView2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btnView2.frame=CGRectMake(0,0,460,460 );
[scrollView1 addSubview:btnView2];
scrollView1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[scrollView1 addSubview:ImageView];
[ImageView release];
}
[self layoutScrollImages]; // now place the photos in serial layout within the scrollview
}
-(IBAction)View:(id)sender{
NSURL *imgUrl=[[NSURL alloc] initWithString:#"http://farm4.static.flickr.com/3567/3523321514_371d9ac42f.jpg"];
NSData *imgData = [NSData dataWithContentsOfURL:imgUrl];
UIImage *img = [UIImage imageWithData:imgData];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
[self.view addSubview:imgView];
//[self.navigationController pushViewController:ivc animated:YES];
[imgUrl release];
}
Instead of adding Imageview and transparent button on top of Imageview. You can just add UIButton customtype and set button image to your image in your scrollview. There is no need to take imageview and UIButton both. Just take UIButton and setImage and you will be fine. I tried to give you sample code below from my app. Please modify it as per your need. I think it is what you need.
First of Take all constant in one of global file. I took it in en.lproj. like below.
"TotalThumbnailCount"="6";
"Coloumn"="2";
"ThumbnailHeight"="151";
"ThumbnailWidth"="151";
//Marging between two images
"MarginX" = "6";
"MarginY" = "6";
Then initialize all your local varaibles from global variables. like below
-(void)PopulateVariables{
TotalThumbnail = [NSLocalizedString(#"TotalThumbnailCount",nil) intValue];
Colomn = [NSLocalizedString(#"Coloumn",nil) intValue];
ThumbnailHeight = [NSLocalizedString(#"ThumbnailHeight",nil) intValue];
ThumbnailWidth = [NSLocalizedString(#"ThumbnailWidth",nil) intValue];
MarginX = [NSLocalizedString(#"MarginX",nil) intValue];
MarginY= [NSLocalizedString(#"MarginY",nil) intValue];
}
Now, you should initiate your thumbnail images using UIButton from below function.
-(void)PopulateThumbnails
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
XCordinate=MarginX;
YCordinate = MarginY;file:
for(int i=1; i <=TotalThumbnail;i++){
UIButton *btnMenu = [UIButton buttonWithType:UIButtonTypeCustom];
//NSData *data =UIImageJPEGRepresentation(, 1);
[btnMenu setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.png",i]] forState:UIControlStateNormal];
CGRect frame = btnMenu.frame;
frame.size.width=ThumbnailWidth;
frame.size.height=ThumbnailHeight;
frame.origin.x=XCordinate;
frame.origin.y=YCordinate;
btnMenu.frame=frame;
btnMenu.tag=i;
btnMenu.alpha = 1;
[btnMenu addTarget:self action:#selector(btnSelected:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:btnMenu];
XCordinate = btnMenu.frame.origin.x + btnMenu.frame.size.width + MarginX;
if(i%Colomn==0)
{
XPosition = XCordinate;
YCordinate = btnMenu.frame.origin.y + btnMenu.frame.size.height + MarginY;
XCordinate = MarginX;
}
}
[pool release];
}
And then set your scrollview contentsize
scrollView.contentSize = CGSizeMake(XPosition, YCordinate);
When some one tap on any image it will goes in below event.
-(IBAction)btnSelected:(id)sender{
UIButton *btnSelected = sender;
switch (btnSelected.tag) {
}
Let me know if I miss anything and if you don't understand.. Hope this help.
You can add UITapGestureRecognizer to each image:
UITapGestureRecognizer *tapGesture = [[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapAction:)] autorelease];
[imageView addGestureRecognizer:tapGesture];
[self.view addSubview:imageView];
When you create your imageview, create a uibutton and add it as a subview to the imageview.
Set the properties of the button to be custom type. Also set the frame of the button same as that of the imageview.
button = [UIButton buttonWithType:UIButtonTypeCustom];
Google how to create a uibutton programatically. You can then add the necessary selectors to handle button press events.
Alternatively you can create a element in Interfacebuilder. A custom class which has a uiimageview and clear uibutton. You can then use this element to add to your uiscrollview.

Zoom UIScrollView with multiple images

I have a UIScrollFrame that contains multiple UIImageViews.
What is the correct way of supporting zoom in such a control?
Which view should 'viewForZoomingInScrollView' return?
I finally implemented it by putting a scrollview within a scrollview.
This way, the inner view handles page swipes while the outer handles zoom.
Apple has a really nice piece of Sample Code that is all about UIScrollView and zooming and tiling. Check it out at
http://developer.apple.com/iphone/library/samplecode/ScrollViewSuite/index.html
This code is discussed in the Scoll Views session of WWDC2009. The video of that session is unfortunately not freely available, but you can buy it as part of the iPhone WWDC2009 video package.
Just put a scrollview within another.
Like that:
-(void)zoomToSelectedImage:(NSIndexPath *)indexPath
{
int currentPage = indexPath.row;
//The External Scrollview. It move back and forward
UIScrollView *contentViewZoom = [[UIScrollView alloc] initWithFrame:self.frame];
[contentViewZoom setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.8]];
[contentViewZoom setContentSize:CGSizeMake(contentViewZoom.frame.size.width * [arrayOfImages count], contentViewZoom.frame.size.height)];
[contentViewZoom setPagingEnabled:YES];
[contentViewZoom setDelegate:self];
for (int i = 0; i < [arrayOfImages count]; i++) {
CGRect frame;
frame.origin.x = contentViewZoom.frame.size.width * i;
frame.origin.y = 0;
frame.size = contentViewZoom.frame.size;
//The Internal Scrollview. It allow you zoom the picture
UIScrollView *imageScrollView = [[UIScrollView alloc]initWithFrame:frame];
[imageScrollView setTag:1];
[imageScrollView setMinimumZoomScale:1.0];
[imageScrollView setMaximumZoomScale:3.0];
[imageScrollView setAlpha:1];
[imageScrollView setDelegate:self];
[imageScrollView setBouncesZoom:YES];
[imageScrollView setClipsToBounds:YES];
[imageScrollView setShowsHorizontalScrollIndicator:NO];
[imageScrollView setShowsVerticalScrollIndicator:NO];
[imageScrollView setContentSize:CGSizeMake(768, 1024)];
UIImage *image = [arrayOfImages objectAtIndex:i];
UIImageView* imgView = [[UIImageView alloc] init];
[imgView setImage:image];
[imgView setFrame:CGRectMake(0, 0, 768, 1024)];
imgView.bounds = self.bounds;
[imgView setClipsToBounds:YES];
[imgView setContentMode:UIViewContentModeScaleAspectFit];
[imgView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[imageScrollView addSubview:imgView];
[contentViewZoom addSubview:imageScrollView];
}
[self addSubview:contentViewZoom];
[contentViewZoom setAlpha:0.2];
//Positioning according to current position
CGRect frame;
frame.origin.x = contentViewZoom.frame.size.width * currentPage;
frame.origin.y = 0;
frame.size = contentViewZoom.frame.size;
[contentViewZoom scrollRectToVisible:frame animated:NO];
}
OBS.: In my case, the screen size is fixed (768x1024), you should change as you need.