使用Uiactivityviewcontroller共享图像

时间:2012-10-05 11:24:02

标签: iphone ios6

如何使用ActivityViewController从imagescrollview共享图像。

以下是在imagescrollview

中显示图像的代码
UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
   imageScrollView.pagingEnabled = YES;
NSInteger numberOfViews = 61;
for (int i = 0; i < numberOfViews; i++) {
    CGFloat xOrigin = i * self.view.frame.size.width;
NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);
 [imageScrollView addSubview:imageView];

尝试使用activityviewcontroller从imagescrollview分享图像,但是在第一个语句中获取红色预期表达式的消息

NSArray *activityItems = @[UIImage imageNamed:]imageView];// **getting message in red expected expression**
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePrint ];
[self presentViewController:activityViewController animated:YES completion:NULL];
[activityViewController release];

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

首先将图像存储在forLoop中,然后将图像添加到scrollview,然后

NSArray *activityItems = [NSArray arrayWithArray:imageArray];  //imageArray is the nsmutablearray in which you shall store the images

答案 1 :(得分:1)

您正在将图像分配给Array的对象,您的语法也是错误的.. 所以这就是为什么你得到以红色预期表达式获取消息这个..

尝试使用此代码而不是代码

NSMutableArray * activityItems = [[NSMutableArray alloc]init];
for (int i = 0; i < numberOfViews; i++) {
    CGFloat xOrigin = i * self.view.frame.size.width;
    NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);
    [imageScrollView addSubview:imageView];
    [[activityItems addObject:imageView];
}
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePrint ];
[self presentViewController:activityViewController animated:YES completion:NULL];
[activityViewController release];