答案 0 :(得分:60)
它不在UIActionSheet
UIActivityController
中,这是iOS中的默认功能。
<强>目标-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];
}
<强>夫特强>
let shareText = "Hello, world!"
if let image = UIImage(named: "myImage") {
let vc = UIActivityViewController(activityItems: [shareText, image], applicationActivities: [])
present(vc, animated: true, completion: nil)
}
尝试使用这些链接进行教程
答案 1 :(得分:3)