2012-09-05 31 views
2

我希望在它所在的位置重新調整按鈕的大小並延遲它,請你幫助我嗎? (發件人=的UIButton)目標C按鈕調整大小和延遲

我的功能:

-(IBAction)Animate: (id) sender 
{ 

[sender setBackgroundImage:[UIImage imageNamed:@"Text Bg large.png"] forState:UIControlStateNormal]; 
CABasicAnimation *scale; 
scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 
scale.fromValue = [NSNumber numberWithFloat:1]; 
scale.toValue = [NSNumber numberWithFloat:1.3]; 
scale.duration = 1; 
scale.removedOnCompletion = NO; 

scale.repeatCount = 1; 
[sender addAnimation:scale forKey:@""]; 
[sender setFrame:(CGRectMake(x, y, z, w))]; 


} 

做我用X,Y,Z什麼,W如果我想這個按鈕將保持在相同的位置,併成長1.3倍大不手動輸入值。哦,我怎麼能延遲這個操作?

+0

動畫已經擴展到1.3倍,是不是?你究竟想在這裏做什麼,哪些不起作用? –

+0

是的,動畫是縮放它。但是在動畫結束之後,它會縮小到原始大小,並且我希望在動畫之後以新大小修復它。 – DanM

+1

啊,對,理解。我的核心動畫是生鏽的:) –

回答

2

有你使用CAAnimation這樣做的原因嗎?

如何:

CGRect newFrame = CGRectInset(sender.frame, CGRectGetWidth(sender.frame) * -0.15, CGRectGetHeight(sender.frame) * -0.15); 

[UIView animateWithDuration: 1.0 
         delay: 0.5 
        options: UIViewAnimationOptionCurveLinear 
       animations:^{ 
        [sender setFrame: newFrame]; 
       } 
       completion: nil]; 

[UIView animateWithDuration: 1.0 
         delay: 0.5 
        options: UIViewAnimationOptionCurveLinear 
       animations:^{ 
        [sender setTransform: CGAffineTransformMakeScale(1.3, 1.3)]; 
       } 
       completion: nil]; 
0

這樣做:

-(IBAction)Animate:(id) sender 
{ 
    UIButton *btnAnimate = (UIButton *)sender; 
    btnAnimate.transform = CGAffineTransformIdentity; 
    [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
    btnAnimate.transform = CGAffineTransformMakeScale(1.3f, 1.3f); 

    } completion:^(BOOL finished){ 

    [btnAnimate setFrame:(CGRectMake(x, y, z, w))]; 

    }]; 
} 
+0

謝謝,但我如何設置新的位置? – DanM

+0

你究竟想要什麼? –

+0

動畫之後,CGRectMake(x,y,z,w)發生。我需要把一些價值,而不是x,y,z,w。我不希望以CGRectMake(50,50,120,180)爲例。我希望它是動態的,按鈕將保持在相同的位置。 – DanM