2013-01-06 83 views
4

我正在尋找複製iOS應用程序中常見的縮放動畫/縮小動畫(例如#1,#2)。我專門尋找一個可以爲某些理想的動畫提供預先指定值的通用庫的源代碼。就像放大一樣,它應該帶有預先配置的變換值,這些變換值可以被人眼很容易地識別。像流行動畫等。如何使用Objective C在iOS上動畫放大/縮小?

我認爲這些必須在iOS中得到很好的支持,無論是通過庫還是直接的API支持......但我不知道哪裏可以開始。

回答

1

我一直在尋找,考慮到我給的例子,是一個抽象層,將給我最常用的動畫類型。

這樣的類型可以使開發人員不僅可以包含常用動畫,如放大/縮小,還可以包含最佳動畫值(To,From,Timing等),以便開發人員不必擔心這些。我發現one such library here,我相信還有更多。

11

像這樣的動畫可以在不需要第三方庫的情況下完成。

例子:

self.frame = CGRectMake(0.0f, 0.0f, 200.0f, 150.0f); 
[UIView beginAnimations:@"Zoom" context:NULL]; 
[UIView setAnimationDuration:0.5]; 
self.frame = CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f); 
[UIView commitAnimations]; 

示例使用規模也

UIButton *results = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 100, 100)]; 
[results addTarget:self action:@selector(validateUserInputs) forControlEvents:UIControlEventTouchDragInside]; 
[self.view addSubview:results]; 

results.alpha = 0.0f; 
results.backgroundColor = [UIColor blueColor]; 
results.transform = CGAffineTransformMakeScale(0.1,0.1); 
[UIView beginAnimations:@"fadeInNewView" context:NULL]; 
[UIView setAnimationDuration:1.0]; 
results.transform = CGAffineTransformMakeScale(1,1); 
results.alpha = 1.0f; 
[UIView commitAnimations]; 

來源:http://madebymany.com/blog/simple-animations-on-ios

+0

謝謝,我知道這一點。然而,這是我可以提及的最簡單的一種。我正在尋找最具有視覺吸引力的常見類型,以便用戶甚至不必使用值。 –

+1

@NiravBhatt你在找什麼常見類型?您在問題中提供的信息越多,我們可以爲您提供更好的幫助? 「用戶」使用這些值的含義是什麼?您是API的用戶還是應該能夠在應用程序中自定義其動畫的實際最終用戶? –

+0

如果我是最終用戶,我不應該玩價值 - 這就是我常用的動畫。 –

13

使用以下代碼放大和縮小動畫。

對於放大:

- (void)popUpZoomIn{ 
popUpView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001); 
[UIView animateWithDuration:0.5 
       animations:^{ 
        popUpView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0); 
       } completion:^(BOOL finished) { 

       }]; 
} 

對於縮小:

- (void)popZoomOut{ 
[UIView animateWithDuration:0.5 
       animations:^{ 
        popUpView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001); 
       } completion:^(BOOL finished) { 
        popUpView.hidden = TRUE; 
       }]; 
} 
+0

請閱讀評論和其他答案。這不是我正在尋找的。 –

+1

真棒答案....它節省了我的時間。 –

2

應用在Xcode中7和iOS 9

//for zoom in 
    [UIView animateWithDuration:0.5f animations:^{ 

     self.sendButton.transform = CGAffineTransformMakeScale(1.5, 1.5); 
    } completion:^(BOOL finished){ 

    }]; 
    // for zoom out 
     [UIView animateWithDuration:0.5f animations:^{ 

      self.sendButton.transform = CGAffineTransformMakeScale(1, 1); 
     }completion:^(BOOL finished){}];