2013-05-19 80 views
1

我有一個動畫矩形,生長在長:動畫一個UIView

[UIView animateWithDuration:60 
       animations:^{ 
       CGRect frame = left.frame; 
       // adjust size of frame to desired value 
       frame.size.height -= 0.1; 
       left.frame = frame; // set frame on your view to the adjusted size 
       } 
       completion:^(BOOL finished){ 
       // Re-start the animation if desired 
       }]; 

然而,矩形只會改變它的高度,以使其向下,而不是向上。我怎樣才能改變它,使矩形向上長大?

+0

接受的答案。 – Fogmeister

回答

1

你只是在改變框架的高度。這將保持相同的x和y原點值。

你需要從零高度至循環改變高度和原點,像htis ...

[UIView animateWithDuration:60 
       animations:^{ 
        CGRect frame = left.frame; 
        // adjust size of frame to desired value 
        frame.size.height -= 0.1; 
        frame.origin.y += 0.1; // make opposite to origin as to height 
        left.frame = frame; // set frame on your view to the adjusted size 
       } 
       completion:^(BOOL finished){ 
        // Re-start the animation if desired 
       }]; 

100高度(例如)

- (void)animateHeight 
{ 
    [UIView animateWithDuration:60 
          delay:0.0 
         options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat 
        animations:^{ 
         CGRect frame = left.frame; 
         // adjust size of frame to desired value 
         frame.size.height = 100; 
         frame.origin.y -= 100; // make opposite to origin as to height 
         left.frame = frame; // set frame on your view to the adjusted size 
        } 
        completion:^(BOOL finished){ 
         // animation is auto reversing and repeating. 
        }]; 
} 
+0

它提出了一個錯誤,說'沒有成員在'struct CGRect'中命名中心。 – user2397282

+0

對不起,我編輯過,我意識到它不會這樣工作:D – Fogmeister

+0

再次編輯,再次修復並添加評論。 – Fogmeister