iOS:MFMailComposeViewController可以附加动画吗?

时间:2013-06-26 13:22:46

标签: iphone ios objective-c mfmailcomposeviewcontroller

我正在研究将图像附加到MFMailComposeViewController一切都很好但我想知道是否可以给出附件动画?

对于Ex: - 当我们在iPhone设备中附加照片库中的图像时。并选择邮件按钮,所有选中的图像在MailComposeViewcontroller中移动,其中包含Nice ANIMATION

所以,任何伙伴都可以指导我这些东西是否有可能。如果是,那么我该如何设置动画附件。

2 个答案:

答案 0 :(得分:2)

存在一些半解决方案。实际上,您可以添加任何UIView作为主应用程序窗口的子视图。它将超越所有应用内容。使用此功能,您可以模拟将图像附加到MailComposeViewcontroller

的动画

请参阅我的示例代码。此代码将图像视图从屏幕顶部滑动到邮件编辑器,因此它模仿添加图像作为附件。一切都被评论了。

//  Get apps main window
UIWindow *window = [[UIApplication sharedApplication] keyWindow];

//  Setup frames of animated image view in apps window - adjust to your needs
CGRect finalImageFrame = CGRectMake(30, 220, window.frame.size.width-60, 100);
CGRect initialImageFrame = finalImageFrame;
initialImageFrame.origin.y = -initialImageFrame.size.height;

//  Create image view to be animated as attachment
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage"]];
imageView.frame = initialImageFrame;
imageView.backgroundColor = [UIColor redColor];

//  Add animated image view to window
[window addSubview:imageView];

//  Animate image view with slide in from top
[UIView animateWithDuration:0.4
                 animations:^{
                     imageView.frame = finalImageFrame;
                 }];

//  Present mail composer
[self presentViewController:mailComposer animated:YES completion:^{

    //  Once the controller appears, hide the image view - adjust this animation according to you needs
    [UIView animateWithDuration:0.4
                     animations:^{
                         imageView.alpha = 0;
                     } completion:^(BOOL finished) {
                         [imageView removeFromSuperview];
                     }];

}];

当然,代码可能需要一些调整和抛光,但它显示了这个概念。您可以使用动画来获得更好的效果。我会添加很多动画调整,但我想保持示例代码的简短,可以; - )

答案 1 :(得分:1)

这是iOS自定义动画效果,并且不会作为iOS API公开,所以不能让你无法获得这种效果。我知道这种效果不会暴露给开发人员的原因来自Apple iOS 6 Docs。只有一种方法可以处理animate及其标准方法。

你能尝试的是这个。在用户从他的照片库(即ALAssetsLibrary)中选择了图像后,您可以为看起来像MFMailComposeViewController的“图像”制作动画。动画类似于iOS提供的内容,即背景淡出,MFMailComposeViewController出现,以及图像位于邮件的“正文”部分。动画完成后,删除MFMailComposeViewController的“图片”,并显示使用MFMailComposeViewController选项调用的实际调用animaiton:FALSE。希望我很清楚。基本上你提供的是MFMailComposeViewController的幻觉,一旦完成动画,就会消除幻觉并展示现实。

理论上这可以起作用,但必须测试精确的动画定时和用户感知的感觉。