I am Using UIImageView in UIScrollView to display Image gallery.
Here is my Code :
[scrollView1 setBackgroundColor:[UIColor blackColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView1.clipsToBounds = YES;
scrollView1.scrollEnabled = YES;
scrollView1.pagingEnabled = YES;
NSUInteger i;
for (i = 0; i <= kNumImages; i++)
{
imageView.userInteractionEnabled = YES;
imageName = [NSString stringWithFormat:@"image%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeScaleAspectFit;
CGRect rect = imageView.frame;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
}
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
rect.size.height = kScrollObjHeight_ipad;
rect.size.width = kScrollObjWidth_ipad;
}
imageView.frame = rect;
imageView.tag = i;
[scrollView1 addSubview:imageView];
}
Now i have a save button to save image in library. for that i have to find every image tag on scrolling. I thought it can be possible by detecting a swipe gesture on UIImageView and can get imageView.tag.
I searched many thing but didn’t get much luck. I understand only is it is difficult to recognize swipe in scroll.
I am new to this Gesture things. Can anyone suggest me what to do?
IS there any other way to get particular imagetag ? Or if i have to go with only this Gesturing thins then how ?
Any help would be a great help..!
Thank you.
In my opinion, you have a couple of options:
1.
Add a UISwipeGestureRecognizer to you UIImageView, and in it’s action method change the imageView’s image. For example
And then just save the imageView’s image.
2.
The other option would be to set the imageView’s frame according to the number of images and then simpy get the imageView’s X coordinate to calculate what image it is displaying.For example,
Then get the scoll’s position to figure out which image is displaying.
Also, I think another way to do this would be to implement the scrollView’s delegate and in the method
have a variable to count how many times the user has scrolled and then calculate what image is displaying. Don’t forget to set