2012-05-15 168 views

回答

22

我有一個很好的想法是如何工作的(我的Shazam的工作,並寫了這個動畫)所以...

雖然我懷疑你想擁有的Shazam的所有版本的細微之處的動畫,我會解釋基本的想法。

首先動畫由五個主要部分組成。

  1. 一個CAShapeLayer形成圓
  2. ,使我們的動畫時間一CABasicAnimation
  3. ,它告訴我們的形狀圖層中的計時器重繪
  4. 遮罩層,將旋轉和掩蓋我們的形狀層
  5. ,關於形狀層的頂部位於標誌(它不必是沙札姆)

所以首先創建CAShapeLayer

CAShapeLayer *newPieLayer = [CAShapeLayer layer];  

[newPieLayer setFillColor:[UIColor blackColor].CGColor]; 

[[self layer] addSublayer:newPieLayer]; 

return newPieLayer; 

創建遮罩層,並將其添加到圈子層,你的面具形象應該掃盡從零阿爾法100%α

self.maskLayer = [CALayer layer]; 
[self.maskLayer setBounds:self.bounds]; 
[self.maskLayer setPosition:CGPointMake(self.bounds.size.width/ 2, self.bounds.size.height/2)]; 
[self.maskLayer setContents:(id)[UIImage imageNamed:kMaskImageName].CGImage]; 

newPieLayer.mask = self.maskLayer; 

一圈創建,將讓我們在同步動畫並把它添加到遮罩層

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
    anim.fromValue = [NSNumber numberWithFloat:startRadians]; 
    anim.toValue = [NSNumber numberWithFloat:M_PI * 2]; 
    anim.duration = timeInterval; 
    anim.delegate = delegate; 
    anim.TimingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 

    [maskLayer addAnimation:anim forKey:kMaskRotationAnimationKey]; 

創建並啓動,我們希望從

做我們繪製的計時器
[NSTimer scheduledTimerWithTimeInterval:kAnimationFireRate target:self selector:@selector(updateTimerFired:) userInfo:nil repeats:YES]; 

在計時器回調設置的路徑爲層

float rotation = [[[maskLayer presentationLayer] valueForKeyPath:@"transform.rotation.z"] floatValue]; 

decibelPath = CGPathCreateArc(animationCenter, inRadius, endAngle, rotation); 

[self.layerOne setPath:decibelPath]; 

現在,你應該有一些看起來非常相似

+1

謝謝尼爾分享你的想法,這一定會幫助我。 – Rachit

+1

您可以請定義:CGPathCreateArc? –

1

iOS沒有設置動畫加載屏幕的功能。你做什麼是你創建一個視圖,當你的應用程序第一次啓動,最初顯示加載圖像。然後,您可以製作該視圖。

請不要這樣做,除非你真的加載了一些東西。 iOS應用程序旨在儘快啓動。加載屏幕旨在成爲您看到的第一個屏幕的近似值,以便儘快將用戶定位到界面。這是而不是出於品牌的目的。

+1

感謝您的意見。其實我想顯示它,而數據從服務器加載時。 – Rachit

0

嗨實現這個邏輯的MonoTouch可以使用邏輯希望這樣你就可以得到你的解決方案

private UIImageView splashScreen; 
public override void ViewDidLoad() { 
#region Splash Screen 
// get the Height & Width of device Screen 
float mainSrcWidth = this.View.Bounds.Width; 
float mainSrcHeight = this.View.Bounds.Height; 
splashScreen = new UIImageView (UIImage.FromFile ("Images/loading.gif")); 
splashScreen.Frame = new RectangleF (0, 0, mainSrcWidth, mainSrcHeight);  
//Start the thread; 
ThreadPool.QueueUserWorkItem (delegate { 
Load(); 
} 
     ); 
#endregion 
#region Load() splashscreen 
private void Load() 
{ 
     //Sleep for 5 seconds to simulate a long load. 
Thread.Sleep (new TimeSpan (0, 0, 0, 5)); 
     this.BeginInvokeOnMainThread (delegate { 
splashScreen.RemoveFromSuperview(); 
      splashScreen = null; 
      }); 
    } 
    #endregion 
相關問題