0

I have a scrollview of images, I will like to tab them and will pushed to another view.

once i tab on the image, the whole view should push to another view. this my ScrollView.h as the following

@interface PeekPagedScrollViewController : UIViewController <UIScrollViewDelegate>

@property (nonatomic, strong) IBOutlet UIScrollView *scrollView;
@property (nonatomic, strong) IBOutlet UIPageControl *pageControl;

@end

and this is my images array as follow

- (void)viewDidLoad {
    [super viewDidLoad];

    // Set up the image you want to scroll & zoom and add it to the scroll view
    self.pageImages = [NSArray arrayWithObjects:
                       [UIImage imageNamed:@"photo1.png"],
                       [UIImage imageNamed:@"photo2.png"],
                       [UIImage imageNamed:@"photo3.png"],
                       [UIImage imageNamed:@"photo4.png"],
                       [UIImage imageNamed:@"photo5.png"],
                       nil];

so what i need when user touch the photo go to another detailViewController; for example if selected Photo1 this photo enlarge on another viewcontroller so if anybody knows the solution or suitable tutorial

3 Answers3

1

Better use UITableView and load all images in UITableViewCell using lazy loading, and when you select any image then didSelectRowAtIndexPath will give you index for selected image and in this way you can navigate and pass data from one viewController to nextViewController.

Refer Lazy load images in UITableView

Community
  • 1
  • 1
iSmita
  • 1,292
  • 1
  • 9
  • 24
0

Better use UITableview or GMGridView for this example code following.

[theApp.fullViewModeObject.statusDicts addObjectsFromArray:statusDicts];
[self.navigationController pushViewController:theApp.fullViewModeObject animated:YES];

theApp.fullViewModeObject is fullviewmode class object [theApp.fullViewModeObject.statusDicts] is array for loading image details

Mahe
  • 98
  • 1
  • 8
0

Add a UITapGestureRecognizer to the UIScrollView, set the delegate yourself and then this method should give you the index of the tapped image:

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture{

    CGPoint touchPoint = [gesture locationInView:<yourScrollView>];

    NSUInteger touchedPage = floorf(touchPoint.x / <yourScrollView>.frame.size.width);
    if ([<arrayOfImages> count>] > 1) {

        touchedPage = touchedPage % ([<arrayOfImages> count] - 1);
    }

    NSLog(@"Touched page: %d", touchedPage);

    //Use touchedPage and push the next view controller here

}

To add the gesture recognizer, add these lines into viewDidLoad (or you can use the IB):

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[<yourScrollView> addGestureRecognizer:singleTap];
Yunus Nedim Mehel
  • 12,089
  • 4
  • 50
  • 56
  • please can you told me how to import uitapgesturerecognizer; or which framework i can import – Mohamed Reda Dec 10 '13 at 00:00
  • @MohamedReda Edited my answer, no need to add a framework – Yunus Nedim Mehel Dec 10 '13 at 08:17
  • please i stuck again to how pass the image to the second view i try to put this code on viewDidload `[imageView setImage:chosenImage];` or `self.selectedImage.image = [UIImage imageNamed:self.imageView];` but it's not work; can you help me – Mohamed Reda Dec 11 '13 at 03:41
  • Define a property (a UIImage or UIImageView) called selectedImage for DetailViewController.h file. Then using the code I give you set the selected image like detailViewController.selectedImage = [ objectAtIndex:touchedPage]; and push the new view controller. Now you can use the _selectedImage inside DetailViewController.m file. – Yunus Nedim Mehel Dec 11 '13 at 08:36
  • i use on viewDidload method the following code `//self.imageView.image = [UIImage imageNamed:self.selectedImage]` but not working; this is correct – Mohamed Reda Dec 11 '13 at 11:23
  • please the final question; i know i make headache for you but the animation is very slow; there's solution for that – Mohamed Reda Dec 12 '13 at 00:21
  • Sorry, which animation is slow here? I only posted code for finding the index of the selected image. But other than that you can use the image anyway you want in DetailVC. – Yunus Nedim Mehel Dec 12 '13 at 00:26
  • when i press the image to go to another view the transition is slow – Mohamed Reda Dec 12 '13 at 00:43
  • when i push the view controller i put this code `PassTouchesViewController *ptvc = [[PassTouchesViewController alloc] init]; ptvc.selectedImage = [imageArray objectAtIndex:touchedPage]; [self.navigationController pushViewController:ptvc animated:YES];` so i mentioned animated:yes; so there's a mistake on this – Mohamed Reda Dec 12 '13 at 01:18
  • well, setting a property wont slow down the pushing animation, there is another reason for that. You have to look it up by " push vc animation slow" or performance issue on pushing vc. etc. It is not related to selecting an image or setting a property. – Yunus Nedim Mehel Dec 12 '13 at 08:23