2011-01-12 24 views
0

我試圖在iPad上實現類似於iBook商店的東西。 當你點擊一本書的封面時,它會翻轉並以一種流暢的動作縮放,從書的封面到空背景 - 然後加載內容。與塊中的其他UIViewAnimations混合

我已經嘗試了不同的方法,第一次翻轉,然後縮放,我試圖在animateWithDuration塊內包裝transitionFromView,但我無法讓它看起來不錯。它會做一個然後另一個,或在最後一個情況下做一個,然後'flickr',什麼都不做。

[UIView transitionFromView:fromView 
        toView:toView 
        duration:0.8 
        options:UIViewAnimationOptionTransitionFlipFromRight 
       completion:^(BOOL finished) { 
        if (finished) { 
          [UIView animateWithDuration:0.4 
           animations:^{[fromView setFrame:originFrame];} 
           completion:^(BOOL finished){}]; 
        } 
       }]; 

塊很適合動畫,毫無疑問! 但我怎麼能同時翻轉和縮放呢?

在此先感謝。

回答

0

我已經能夠通過在包含您在之間切換的視圖的視圖上進行翻轉來使用非塊動畫產生此效果。

CGRect endFrame; //The frame of the view after animation 
UIView *sview; //The superview containing the first view 
UIView *view1; //The first view, to be removed from sview 
UIView *view2; //The second view, to be added to sview 

view2.frame = view1.frame; 
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:0.8]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:sview cache:YES]; 
[view1 removeFromSuperview]; 
[sview addSubview:view2]; 
sview.frame = endFrame; 
[UIView commitAnimations]; 

爲此,view2上的自動調整遮罩必須在寬度和高度上可調整大小。

+0

我會在早上第一件事情嘗試一下:)謝謝。我仍然希望有一種方法可以做到這一點。 – RickiG 2011-01-12 21:05:38