2011-12-26 73 views
0

所以我想學習塊的過渡動畫。所以我去了蘋果文檔,並使用old method (without blocks)舉了一個動畫的例子。我已經採取了代碼片段(稍作修改)並對其進行了測試。它完美UIView transistionWithAnimation不起作用

[UIView setAnimationDelegate:nil]; 
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:kTransitionDuration]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight 
           forView:self.view 
           cache:YES]; 

if ([self.instructionsView superview]) { 
    [self.instructionsView removeFromSuperview]; 
    [self.view addSubview:contentView]; 
} else { 
    [self.contentView removeFromSuperview]; 
    [self.view addSubview:instructionsView]; 
} 

[UIView commitAnimations]; 

// adjust our done/info buttons accordingly 
if ([instructionsView superview]) { 
    self.navigationItem.rightBarButtonItem = doneButton; 
} else { 
    self.navigationItem.rightBarButtonItem = flipButton; 
} 

現在下面的代碼是我嘗試將代碼轉換在上面的代碼塊

[UIView transitionWithView:self.view duration:kTransitionDuration options:UIViewAnimationTransitionFlipFromRight animations:^{ 
     if ([self.instructionsView superview]) { 
      [self.instructionsView removeFromSuperview]; 
      [self.view addSubview:contentView]; 
     } else { 
      [self.contentView removeFromSuperview]; 
      [self.view addSubview:instructionsView]; 
     } 
} completion:^(BOOL finished){ 

     if ([instructionsView superview]) { 
      self.navigationItem.rightBarButtonItem = doneButton; 
     } else { 
      self.navigationItem.rightBarButtonItem = flipButton; 
     } 
}]; 

從我所瞭解的是,下面的代碼應該工作。我在支持塊的iOS 4.2上測試這個。然而,它似乎沒有動畫,我不明白這是爲什麼。它改變了觀點,只是不動畫。請幫忙。

回答

0

嘗試用transitionToView替換transitionWithView:fromView