1

我想做一个简单的按钮,更改大小和展开,然后收缩后续点击。iPhone UIButton翻转和展开

它有点作用,翻盖后的最后一个按钮看起来是正确的 - 它是圆形和不同的大小。问题是在转换过程中,我得到了这种奇怪的非循环效应。查看此链接以查看此问题 - >http://screencast.com/t/rJaSJ0nGq

我该如何使过渡平滑并始终看起来是圆形的?我不希望在屏幕录像中出现圆角矩形外观。

这里是我的按钮点击方法:

// Handle when a user presses the button 
- (IBAction)bubblePressed:(id)sender { 

    // Expand the bubble if it's pressed or de-expand it if 
    // already expanded 
    if (buttonResized) { 

     CGRect tempFrame=self.expandMe.frame; 
     tempFrame.size.width=100;//change acco. how much you want to expand 
     tempFrame.size.height=100; 
     [UIView beginAnimations:@"" context:nil]; 
     [UIView setAnimationDuration:BUTTON_FLIP_TIME]; 
     self.expandMe.frame=tempFrame; 

     // Round the buttons 
     self.expandMe.clipsToBounds = YES; 
     self.expandMe.layer.cornerRadius = self.expandMe.frame.size.width/2;//half of the width 
     self.expandMe.layer.borderColor=[UIColor clearColor].CGColor; 
     self.expandMe.layer.borderWidth=2.0f; 

     // Flip the button 
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.expandMe cache:YES]; 

     [UIView commitAnimations]; 

    } 
    else { 

     CGRect tempFrame=self.expandMe.frame; 
     tempFrame.size.width=200;//change acco. how much you want to expand 
     tempFrame.size.height=200; 
     [UIView beginAnimations:@"" context:nil]; 
     [UIView setAnimationDuration:BUTTON_FLIP_TIME]; 
     self.expandMe.frame=tempFrame; 

     // Round the buttons 
     self.expandMe.clipsToBounds = YES; 
     self.expandMe.layer.cornerRadius = self.expandMe.frame.size.width/2;//half of the width 
     self.expandMe.layer.borderColor=[UIColor clearColor].CGColor; 
     self.expandMe.layer.borderWidth=2.0f; 

     // Flip the button 
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.expandMe cache:YES]; 

     [UIView commitAnimations]; 

    } 

    // Flip the variable that tracks flipping 
    buttonResized = !buttonResized; 

} 
+0

我想这'self.expandMe.layer.cornerRadius = self.expandMe.frame.size.width/2'可能是什么原因导致它不够圆。想象一下正方形转向圆形:它应该是一个非线性过程。 – BabyPanda 2012-08-12 15:08:25

回答