转换后重置比例

时间:2014-12-06 16:27:59

标签: ios objective-c cgaffinetransform

_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]返回,其中card是自定义类,并分配给_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的第一种情况(成功查询Parse数据库之后):

[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++;

            }];

1 个答案:

答案 0 :(得分:0)

发现问题 - 动画中调用[self nextCard],但应在完成时调用。

相关问题