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;
}
我想這'self.expandMe.layer.cornerRadius = self.expandMe.frame.size.width/2'可能是什麼原因導致它不夠圓。想象一下正方形轉向圓形:它應該是一個非線性過程。 – BabyPanda 2012-08-12 15:08:25