is there a class to get the default picture viewer in an app?

久未见 提交于 2019-12-05 05:59:43

问题


I don't want to access the images on the iphone, I want to display an image from my app, but like you view pictures in the picture album of the iphone - with all the pinch and zoom controls and such.

Is this possible? I thought there might (by chance) be some class like the AVMediaPlayer class that would do this?

Thanks Tom


回答1:


If you're targeting 4.0 or later you can use QLPreviewController:

Include #import <QuickLook/QuickLook.h> in your class

Here is how to create one:

Class qlookclass = NSClassFromString(@"QLPreviewController");
        if(qlookclass){
            //check if the image exists
            if([[NSFileManager defaultManager] fileExistsAtPath:@"someimage.png"]){
                id quickLookPreview = [[qlookclass alloc]init];
                [quickLookPreview setDataSource:self];
                [self presentModalViewController:quickLookPreview animated:YES];
                [quickLookPreview release];
            }
        }

Then somewhere else in your view controller:

#pragma mark QLPreviewController delegate methods

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller {
    return 1;
}

- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index {

    NSURL *imageURL =  [NSURL fileURLWithPath:@"someimage.png"];

    return imageURL;
}


来源:https://stackoverflow.com/questions/3752731/is-there-a-class-to-get-the-default-picture-viewer-in-an-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!