2013-06-26 45 views
5

我正在附加圖像到MFMailComposeViewController一切都很好,但我想知道這是可能給附件的動畫?iOS:是否可以使用動畫技術來處理MFMailComposeViewController?

例如: -當我們在iPhone設備中添加圖片庫中的圖片時。並選擇郵件按鈕,所有選定的圖片移動在MailComposeViewcontroller與尼斯動畫

所以,請任何好友指導我這個東西是否可能。如果是,那麼我如何設置附件動畫。

+0

不,不可能。 – sagarcool89

+0

不默認。 – Jasper

+0

看到我的答案。它不可能做與蘋果電子郵件完全相同的東西,但你至少可以模擬類似的效果 –

回答

1

這是iOS自定義動畫效果,並沒有公開爲iOS API,所以沒有你無法獲得這種效果。我知道這個效應沒有暴露給開發者的原因是Apple iOS 6 Docs。只有一種方法處理animate及其標準。

你可以嘗試的是這個。在用戶從他的照片庫(即從ALAssetsLibrary)中選擇圖像後,可以爲看起來像MFMailComposeViewController的「圖像」創建動畫。該動畫將與iOS提供的類似,即出現背景淡入淡出,MFMailComposeViewController以及位於郵件「正文」部分的圖像。一旦動畫完成,請刪除MFMailComposeViewController的「圖像」,並顯示使用animaiton:FALSE選項調用的實際呼叫MFMailComposeViewController。希望我清楚。基本上你所提供的是一種幻覺MFMailComposeViewController,一旦動畫完成,帶走錯覺並展示現實。

從理論上講,這可能工作,但確切的動畫時間和用戶感知的感覺必須進行測試。

+0

很好的解釋。可能會很難實現..? –

+0

@NitinGohel的實現並不難。但是你可能不得不動用動畫的時間來獲得正確的效果,這樣用戶就不會感覺到這種轉變。請不要叫我先生!那是什麼人稱我的爺爺! –

+0

最後一條建議。仔細研究ios動畫。仔細觀察哪些元素正在移動/變化/褪色/消失/計時等等。記下它並嘗試將其複製到您的代碼中。它應該很有趣! –

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]; 
        }]; 

}]; 

當然,代碼可能需要一些調整和拋光,但它顯示的概念。你可以玩動畫來產生更好的效果。我會添加很多動畫調整,但我想保持示例代碼儘可能短;-)

相關問題