2014-12-06 55 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。