2011-09-14 76 views
6

我有一個叫做geopointView的UIView。我想在按下按鈕(myButton)時在主視圖框架上在此UIview中爲幻燈片添加動畫。如果再次按下myButton,則UIview應該滑出框架。 myButton的調用下面的方法「optionsCalled」UIView動畫滑入,但不滑出使用塊動畫方法

-(void) optionsCalled 
{ 
if (![[self.view subviews] containsObject:geopointView] &&checkForGeopointViewAnimation ==0) { 

     [self.view addSubview:geopointView]; 
     geopointView.frame = CGRectMake(0,430,320,30); 
     [UIView animateWithDuration:0.3f 
         animations:^{ 
          geopointView.frame = CGRectMake(0, 350, 100, 80); 
         } 
         completion:^(BOOL finished){ 
          checkForGeopointViewAnimation = 1 ; 
         }]; 

    } 
    if ([[self.view subviews] containsObject:geopointView] && checkForGeopointViewAnimation ==1) 
    { 

     geopointView.frame = CGRectMake(0, 350, 100, 80); 
     [UIView animateWithDuration:0.3f 
         animations:^{ 
          geopointView.frame = CGRectMake(0,430,320,30); 
         } 
         completion:^(BOOL finished){ 
          checkForGeopointViewAnimation = 0 ; 
         }]; 

     [geopointView removeFromSuperview]; 

    } 

} 

這裏checkForGeopointViewAnimation被定義爲確保滑動進出沒有一次叫一個全局變量。

此代碼的問題在於,UIview以動畫形式滑動,但不會動畫滑出動作。它只是從主框架消失。我是否需要在這裏使用任何時間,以便在添加和刪除UIview函數時有延遲?

感謝提前

回答

5

任何幫助,嘗試[geopointView removeFromSuperview];動畫

+0

非常感謝,指出.. – alekhine

+1

@amol_subhedar:請投贊成所有幫助你的答案,只是爲了表示讚賞。 – visakh7

4

也許你需要調用[geopointView removeFromSuperview];在你完成,而不是塊的完成後?

+0

感謝您的回答.. – alekhine