【发布时间】:2012-08-12 14:24:36
【问题描述】:
我正在尝试制作一个简单的按钮来更改大小并在后续点击时展开然后缩小。
它有点工作,翻转后的最后一个按钮看起来是正确的 - 它是圆形的并且大小不同。问题是在过渡期间,我得到了这种奇怪的非圆形效果。请参阅此链接以了解此问题 --> 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可能是导致它不够圆的原因。想象一个正方形变成圆形:它应该是一个非线性过程。
标签: iphone objective-c uibutton uiviewanimation uiviewanimationtransition