ios Xcode:通过操作表共享内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31941188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode : sharing content via Action Sheet
提问by Miwi
I would like to replicate this behaviour (see image below) and share contents from my app using this kind of action sheet.
我想复制这种行为(见下图)并使用这种操作表共享我的应用程序中的内容。
The question is:
问题是:
Is this really an Action Sheet? I can't find anywhere tutorial for iOS 7 or 8. Not sure how to proceed.
这真的是行动表吗?我找不到任何适用于 iOS 7 或 8 的教程。不知道如何继续。
Do the sharing options depends on user's configurations?
共享选项是否取决于用户的配置?
Hints would be appreciated.
提示将不胜感激。
回答by Anbu.Karthik
It is not in UIActionSheetit is in UIActivityController, which is the default function in iOS.
it is not in UIActionSheetit is in UIActivityController,这是iOS中的默认功能。
objective-C
目标-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)
}
Try these links for tutorials
试试这些链接的教程
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/
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
迅速
回答by Beyond_Infinity
You can achieve this result by using UIActivityController class.
您可以通过使用 UIActivityController 类来实现此结果。
Please take a look at this link :- http://nshipster.com/uiactivityviewcontroller/
请查看此链接:- http://nshipster.com/uiactivityviewcontroller/
Hope this helps!
希望这可以帮助!


