Programmatically Scroll In Gallery
Dear Allright,
I am trying to have a button in my app that allows the user to advance forward or backwards in the gallery without swiping. For example, pressing the button while on selectedIndex = 1 would move the ASGallery to selectedInde = 6, and then the 7th photo would be shown in the gallery. How would I go about doing something like this? I've tried to play around with and tweak your existing code but am having some problems. Thanks!
Best, Felix
What I am trying to ultimately do is accomplish the following:
-Photo #10 is currently shown on the screen. There are 100 photos. -When a user holds down on Photo #10 for more than 5 seconds, that photo is deleted from the camera roll (or some other action). -I then want Photo #11 to automatically show up on the screen. -When the user scrolls to the left from Photo #11, the former Photo #10 should not be there. Instead, they will see Photo #10.
So essentially, I want to be able to remove photos out of the scrollview and then change the offset so that the next picture shows.
Any help at all would be great. Thank you!
Look at the function viewWillAppear, I think following code may help
you.
CGFloat pageWidth = pagingScrollView.frame.size.width;
CGFloat newOffset = neededIndex * pageWidth;
pagingScrollView.contentOffset = CGPointMake(newOffset, 0);
[pagingScrollView setContentOffset: animated:YES]
So, This is not ASGallery responsibility. But I've decided this problem in my App TimeGallery: https://itunes.apple.com/app/timegallery/id583294307 You have to:
-(void)init { library = [[ALAssetsLibrary alloc] init];
// WORKAROUND from http://openradar.appspot.com/10484334 for receiving ALAssetsLibraryChangedNotification
[library writeImageToSavedPhotosAlbum:nil metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {}];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(assetsLibraryDidChanged:)
name: ALAssetsLibraryChangedNotification
object:library];
}
- (void) assetsLibraryDidChanged { [galleryViewController reloadData]; }
Thank you so much for your quick reply, I just got to work today and will try that out. If the app I'm working on does get published, I'll make sure to give you a shoutout. Much appreciated :)
Last quick question if you know off the top of your head. How would I access the URL of the ALAsset currently shown on the screen? I know it's somewhere in the (loadImage: withImageType:) method of ALAssetAdapter.m, whenever I do a NSLog of the ASGalleryImageType, I get 1 and 2. I think that 2 is the full screen image that is being shown, but more than one image has this ASGalleryImageType. Is there a way for me to add a line in this method so that I can store the URL of the image currently shown on the screen as an instance variable? Thanks!
Hmm, it is not good way to modify loadImage: withImageType: Look inside ASGalleryViewController: (visiblePageForIndex:)
You can add following function:
-(NSURL_)currentAssetURL { ASGalleryPage_ isv = [self visiblePageForIndex:self.selectedIndex] NSURL* url = [isv.asset url]; return url; }
I think you have to make visiblePageForIndex: -> public, and use it in child class or modify ASGalleryViewController.