gpt4 book ai didi

ios - 代码 : sharing content via Action Sheet

转载 作者:IT王子 更新时间:2023-10-29 05:04:23 25 4
gpt4 key购买 nike

我想复制这种行为(见下图)并使用这种操作表分享我的应用中的内容。

enter image description here

问题是:

这真的是行动表吗?我在任何地方都找不到适用于 iOS 7 或 8 的教程。不确定如何继续。

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

将不胜感激。

最佳答案

它不在 UIActionSheet 中,它在 UIActivityController 中,这是 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/

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

  3. 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

关于ios - 代码 : sharing content via Action Sheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31941188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com