2014-12-06 59 views
0
_cardView =[card initCard]; 

[self.view addSubview:_cardView]; 

_cardView.transform=CGAffineTransformScale(CGAffineTransformIdentity, 0.1, 0.1); 
[UIView animateWithDuration:0.3 
       animations:^{ 
        _cardView.transform=CGAffineTransformIdentity; 
       }]; 

我有一個視圖,使其看起來像是從一個點(類似於正在打開的應用程序的動畫)展開看起來。該視圖從[card initCard]返回,卡片是自定義類,並分配給_cardView。使用CGAffineTransformScale我首先減小比例,然後動畫增加比例。這對於顯示的第一張卡完全適用。但是,如果將_cardView設置爲nil並將新卡分配給它,則相同的轉換和動畫代碼會生成錯誤的動畫,這會使視圖在縮小之前增加比例。我認爲問題在於使比例爲0.1,0.1,但我無法解決這個問題。轉換後的重置比例

設置爲nil:

else if (sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled || sender.state == UIGestureRecognizerStateFailed) 
{ 
    if(sender.view.center.x>0){ 
     [UIView animateWithDuration:0.2 animations:^{ 
      CGRect rect=[sender.view frame]; 
      rect.origin.x=([self.view frame].size.width/2)-129.5; 
      [sender.view setFrame:rect]; 
      sender.view.alpha = 0.8; 

     }]; 
    }else{ 
     [UIView animateWithDuration:0.5 animations:^{ 
      _protoypeView.alpha=0.0; 
      _protoypeView=nil; 
      _cardView=nil; 

      [self nextCard]; 
     }]; 
    } 
} 

和功能nextCard:

-(void)nextCard{ 
    if(cardNumber>[questionArray count]-1){ 
     NSLog(@"Out of cards"); 
    }else{ 
     QuestionCard *card=[[QuestionCard alloc]init]; 
     NSArray* array =[[NSArray alloc]initWithArray:questionArray[cardNumber]]; 
     card.questionString=array[3]; 
     card.whenPosted=array[0]; 
     card.isAnon=array[2]; 
     card.user=array[1]; 
     card.replies=array[4]; 
     card.profileImg=array[5]; 
     _cardView =[card initCard]; 
     [self.view addSubview:_cardView]; 
     _cardView.alpha=0.0; 
     _cardView.transform=CGAffineTransformScale(CGAffineTransformIdentity, -1, -1); 
     _cardView.transform=CGAffineTransformIdentity; 
     [UIView animateWithDuration:1 animations:^{ 
      _cardView.alpha=0.7; 
     }]; 

     UIPanGestureRecognizer * pan1 = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePanImage:)]; 
     pan1.minimumNumberOfTouches = 1; 
     [_cardView addGestureRecognizer:pan1]; 
     yOfView=[_cardView frame].origin.y+([_cardView frame].size.height/2); 
     cardNumber++; 

    } 
} 

CGAffineTransform的第一種情況(查詢成功後,解析數據庫):

[UIView animateWithDuration:0.5 animations:^{ 
       _protoypeView.alpha=0.0; 
      }completion:^(BOOL finished){ 
       QuestionCard *card=[[QuestionCard alloc]init]; 
       NSArray* array =[[NSArray alloc]initWithArray:questionArray[cardNumber]]; 
       card.questionString=array[3]; 
       card.whenPosted=array[0]; 
       card.isAnon=array[2]; 
       card.user=array[1]; 
       card.replies=array[4]; 
       card.profileImg=array[5]; 
       _cardView =[card initCard]; 

       [self.view addSubview:_cardView]; 

       _cardView.transform=CGAffineTransformScale(CGAffineTransformIdentity, 0.0, 0.0); 
       [UIView animateWithDuration:0.3 
           animations:^{ 
            _cardView.transform=CGAffineTransformIdentity; 
           }]; 
       UIPanGestureRecognizer * pan1 = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePanImage:)]; 
       pan1.minimumNumberOfTouches = 1; 
       [_cardView addGestureRecognizer:pan1]; 
       yOfView=[_cardView frame].origin.y+([_cardView frame].size.height/2); 
       cardNumber++; 

      }]; 
+0

顯示零件如何從卡上「剔除」以及再次調用該零件。 – Unheilig 2014-12-06 17:03:17

+0

編輯我的問題 – RodMatveev 2014-12-06 17:11:19

+0

這裏有很多事情需要改變;但讓我們繼續關注你的問題:你在哪裏放置第一塊代碼?它不在您剛剛添加的任何代碼中。 – Unheilig 2014-12-06 17:41:26

回答

0

發現問題 - [self nextCard]在動畫中被調用,但應在comp中調用letion。