Xcode:通过操作表共享内容 [英] Xcode : sharing content via Action Sheet

查看:91
本文介绍了Xcode:通过操作表共享内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想复制此行为(请参见下图),并使用此类操作表从我的应用分享内容。

I would like to replicate this behaviour (see image below) and share contents from my app using this kind of action sheet.

问题是:

这真的是一个动作片?我无法找到iOS 7或8的任何教程。不确定如何继续。

Is this really an Action Sheet? I can't find anywhere tutorial for iOS 7 or 8. Not sure how to proceed.

共享选项是否取决于用户的配置?

Do the sharing options depends on user's configurations?

提示将不胜感激。

推荐答案

它不在 UIActionSheet 它位于 UIActivityController 中,这是iOS中的默认功能。

It is not in UIActionSheet it is in UIActivityController, which is the default function in iOS.

objective-C

- (void)presentActivityController:(UIActivityViewController *)controller {

    // for iPad: make the presentation a Popover
    controller.modalPresentationStyle = UIModalPresentationPopover;
    [self presentViewController:controller animated:YES completion:nil];

    UIPopoverPresentationController *popController = [controller popoverPresentationController];
    popController.permittedArrowDirections = UIPopoverArrowDirectionAny;
    popController.barButtonItem = self.navigationItem.leftBarButtonItem;

    // access the completion handler
    controller.completionWithItemsHandler = ^(NSString *activityType,
                                              BOOL completed,
                                              NSArray *returnedItems,
                                              NSError *error){
        // react to the completion
        if (completed) {
            // user shared an item
            NSLog(@"We used activity type%@", activityType);
        } else {
            // user cancelled
            NSLog(@"We didn't want to share anything after all.");
        }

        if (error) {
            NSLog(@"An Error occured: %@, %@", error.localizedDescription, error.localizedFailureReason);
        }
    };
}

-(void)sendMessage {
    //create a message
    NSString *theMessage = @"Some text we're sharing with an activity controller";
    NSArray *items = @[theMessage];

    // build an activity view controller
    UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];

    // and present it
    [self presentActivityController:controller];
}

Swift

let shareText = "Hello, world!"

if let image = UIImage(named: "myImage") {
    let vc = UIActivityViewController(activityItems: [shareText, image], applicationActivities: [])
     present(vc, animated: true, completion: nil)
}

试试这些链接进行教程


  1. http:// nshipster .com / uiactivityviewcontroller /

http://www.codingexplorer.com/add-sharing-to-your-app-via-uiactivityviewcontroller/

http://roadfiresoftware.com/2014/02/how-to-add-facebook-and-twitter-sharing-to-an-ios-app/

Swift

https://www.hackingwithswift.com/example-code/uikit/how-to-share- content-with-uiactivityviewcontroller

这篇关于Xcode:通过操作表共享内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆