Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatically Scroll In Gallery #2

Open
ghost opened this issue Jun 18, 2013 · 6 comments
Open

Programmatically Scroll In Gallery #2

ghost opened this issue Jun 18, 2013 · 6 comments

Comments

@ghost
Copy link

ghost commented Jun 18, 2013

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

@ghost
Copy link
Author

ghost commented Jun 18, 2013

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!

@allright
Copy link
Owner

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]

@allright
Copy link
Owner

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];
    }

@ghost
Copy link
Author

ghost commented Jun 19, 2013

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 :)

@ghost
Copy link
Author

ghost commented Jun 19, 2013

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!

@allright
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant