ios – 加载Adobe Illustrator(.ai)文件

前端之家收集整理的这篇文章主要介绍了ios – 加载Adobe Illustrator(.ai)文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否可以加载.ai文件并以编程方式打开它们?

这是我尝试过的:

- (IBAction)openDocument:(id)sender
{
    QLPreviewController *previewController = [[QLPreviewController alloc] init];
    [previewController setDataSource:self];
    [previewController setDelegate:self];
    [self presentModalViewController:previewController animated:YES];
}

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

- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return [[NSBundle mainBundle] URLForResource:@"CNW EXPLODED1" withExtension:@"ai"];
}

输出是这样的:

解决方法

有一种方法可以做到这一点.这就是将ai的扩展名改为pdf并加载,如下所示,
- (IBAction)openDocument:(id)sender
{
    QLPreviewController *previewController = [[QLPreviewController alloc] init];
    [previewController setDataSource:self];
    [previewController setDelegate:self];
    [self presentModalViewController:previewController animated:YES];
}
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    return [[NSBundle mainBundle] URLForResource:@"CNW EXPLODED1" withExtension:@"pdf"];
}

OUTPUT:

这是完美的工作..但我不想改变EXTENSION.任何人都可以帮助我更多.

**

更新的答案:

- (IBAction)openDocument:(id)sender
{
    UIButton *button = (UIButton *)sender;
    NSURL *URL = [[NSBundle mainBundle] URLForResource:@"CNW EXPLODED1" withExtension:@"ai"];

    if (URL) {
        // Initialize Document Interaction Controller
        self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];

        // Configure Document Interaction Controller
        [self.documentInteractionController setDelegate:self];

        // Present Open In Menu
        [self.documentInteractionController presentOpenInMenuFromRect:[button frame] inView:self.view animated:YES];
    }
}


- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
    return self;
}

显示菜单选项,但有选项BUMP.它仅适用于设备

**

原文链接:https://www.f2er.com/iOS/334318.html

猜你在找的iOS相关文章