2011-08-04 174 views
4

我開始嘗試重新從應用程序商店購買按鈕,需要2階段點擊購買的東西。我爲擴展按鈕設置動畫。到目前爲止,我有這個UIView動畫更改大小的按鈕

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:0.75]; 

sender.autoresizesSubviews = NO; 
sender.clipsToBounds = NO; 
sender.frame = CGRectMake(63,326,200,37); 

[UIView commitAnimations]; 

這只是導致按鈕變得更大,它不動畫在所有。我做錯了什麼或有其他人實現了這種類型的按鈕行爲?

編輯:

- (IBAction) buyButtonAction: (UIButton *) sender { 

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1.5]; 
[UIView setAnimationDelay:0.5]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 

sender.clipsToBounds = NO; 

sender.frame = CGRectMake(CGRectGetMinX(sender.frame) - 30, CGRectGetMinY(sender.frame), 200, 37); 
[sender setTitle:@"Touched Touched Touched" forState:UIControlStateNormal]; 


[UIView commitAnimations]; 
} 

回答

7

你瞄準的是不支持塊在iOS?

我已經實施了一個「按鈕動畫觸摸」使用下面令人反胃的簡單代碼。

[UIView animateWithDuration:0.5 animations:^{ 
    self.navigationItem.rightBarButtonItem.title = @"Quoting..."; 
}]; 

另外,該代碼似乎工作,以及動畫觸摸一個按鈕,如果你不能支持塊(還包括評論,如果你走這條路線的塊):

-(IBAction) clicked:(UIButton*)sender{ 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationDelay:0]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    //[UIView animateWithDuration:2.5 animations:^{ 

    sender.autoresizesSubviews = NO; 
    sender.clipsToBounds = NO; 
    sender.frame = CGRectMake(63,326,200,37); 

    //sender.frame = CGRectMake(CGRectGetMinX(self.theButton.frame) - 100, CGRectGetMinY(self.theButton.frame), 300, 40); 
    //[sender setTitle:@"Touched Touched Touched" forState:UIControlStateNormal]; 
//}]; 
+0

我想我一定在做錯事。我使用了您提供的更長的片段,現在尺寸立即發生變化,然後唯一動畫就是移動按鈕的位置?!?!我已經對原始帖子進行了編輯,向您展示了代碼的位置。 – Josh

+0

我把你的屬性更改放到我的示例代碼中,取出setTitle,因爲我不認爲這部分動畫適當。我放置了一個位置 - 30爲我的代碼的按鈕的X座標。我會編輯我的代碼來使用你的動畫,也許這將提供有用的結果。 – LrdCasimir

+0

太棒了,謝謝。不知道什麼是最初的錯誤,但現在得到它排序謝謝。 – Josh