سؤال

The last couple of days I've tried to implement a Photo Viewer in my iOS 5.0 Application in Xcode 4.2. By project is running with Automatic Reference Counting (ARC). I've tried Three20 Photo Viewer but this has a lot of dependencies and is really a heavy piece to include in my project. Next I've tried EGOPhotoViewer which really seems as a great solution for my purpose -- but sadly I does not support ARC and because of that, I cannot compile it inside my project.

Does anybody know a Photo Viewer for iOS which supports ARC -- or could, in some way, be added as a library to a project running with ARC?

هل كانت مفيدة؟

المحلول

It is possible to disable ARC for individual files by adding the -fno-objc-arc to a file.

To disable ARC for a file select your project in Xcode 4, go to the build phases tab, select the files you want to disable for ARC, add the -fno-objc-arc compiler flag to these files.

نصائح أخرى

You might want to take a look at MWPhotoBrowser - you can add it to your project as a static library which will work independantly of your project's ARC settings.

MWPhotoBrowser can display one or more images by providing either UIImage objects, or URLs to files, web images or library assets. The photo browser handles the downloading and caching of photos from the web seamlessly. Photos can be zoomed and panned, and optional (customisable) captions can be displayed. The browser can also be used to allow the user to select one or more photos using either the grid or main image view.

MWPhotoBrowser Screenshots

Here's how I did it:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
  self.startX = scrollView.contentOffset.x;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
  //NSLog(@"scrollViewDidEndDragging");
  self.endX = scrollView.contentOffset.x;

  self.photoIdx = (int)self.startX / Normalize(1160);

  if (decelerate == FALSE)
  {
    int intoThePhoto = (int)self.photoScrollView.contentOffset.x % Normalize(1160);

    if (intoThePhoto < Normalize(1060/2))
      [scrollView setContentOffset:CGPointMake(Normalize(1160)*self.photoIdx,0) animated:YES];
    else
      [scrollView setContentOffset:CGPointMake(Normalize(1160)*(self.photoIdx+1),0) animated:YES];

  }

}

-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{

  if ((self.endX - self.startX) > 0 && self.photoIdx < ([self.photos count] -1))
    [scrollView setContentOffset:CGPointMake(Normalize(1160)*(self.photoIdx+1),0) animated:YES];
  else if ((self.endX - self.startX) < 0 && self.photoIdx != 0)
    [scrollView setContentOffset:CGPointMake(Normalize(1160)*(self.photoIdx-1),0) animated:YES];
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top