gpt4 book ai didi

iphone - 自定义 UIActivityViewController

转载 作者:行者123 更新时间:2023-12-03 19:52:07 30 4
gpt4 key购买 nike

我正在尝试将屏幕截图附加到我的 UIActivityViewController 中的邮件中,而不将屏幕截图保存到我的库中。到目前为止,这是我的代码:

-(IBAction)ActivityController:(id)sender {{



NSString *shareString = @"";
UIImage *shareImage = [UIImage imageNamed:@""];


NSURL *shareUrl = [NSURL URLWithString:@""];
NSArray *activityItems = [NSArray arrayWithObjects:shareString,shareImage, shareUrl, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:activityViewController animated:YES completion:nil];

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];

mailController.mailComposeDelegate = self;
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *exportData = UIImageJPEGRepresentation(image ,1.0);
[mailController addAttachmentData:exportData mimeType:@"image/jpeg" fileName:@"Screenshot.jpeg"];

电子邮件中没有附加屏幕截图。

当我按下 UIActivityViewcontroller 中的取消按钮时,如何创建操作?

最佳答案

UIActivityViewController帮助您轻松共享iOS6中的数据。只需调用它,输入数据,然后单击您要共享的那个即可。不要初始化 MFMailComposeViewController。

这是在 iPad 和 iPhone 上运行的示例通用代码

-(IBAction)actionButton:(id)sender {
//Popover for iPad
//if (self.popover) {
// if ([self.popover isPopoverVisible]) {
// return;
// } else {
// [self.popover dismissPopoverAnimated:YES];
// self.popover = nil;
// }
// }

UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSString *shareText = @"Share Text";
NSURL *shareURL = [NSURL URLWithString:@"http://shareURL.com"];

/* iOS 6 sharing, */
UIActivity *activity = [[UIActivity alloc] init];

NSArray *activityItems = @[image, shareText, shareURL];
NSArray *applicationActivities = @[activity];
NSArray *excludeActivities = @[];

UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityController.excludedActivityTypes = excludeActivities;

// switch for iPhone and iPad.
// if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// self.popover = [[UIPopoverController alloc] initWithContentViewController:activityController];
// self.popover.delegate = self;
// [self.popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
// } else {
[self presentViewController:activityController animated:YES completion:^{
NSLog(@"Activity complete");
}];
// }


}

编辑如果你想知道什么时候取消按钮点击,你需要在presentViewController中稍微修改一下

    [self presentViewController:activityController animated:YES completion:nil];
[activityController setCompletionHandler:^(NSString *act, BOOL done)
{
if (!act) {
NSLog(@"Cancel");
}
}];

关于iphone - 自定义 UIActivityViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18147506/

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