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

允我心安 提交于 2019-12-03 21:12:05

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